diff --git a/cellxgene_gateway/prune_process_cache.py b/cellxgene_gateway/prune_process_cache.py
index f332ffd..98126ec 100644
--- a/cellxgene_gateway/prune_process_cache.py
+++ b/cellxgene_gateway/prune_process_cache.py
@@ -10,14 +10,16 @@
import logging
import time
-from cellxgene_gateway.env import ttl
-from cellxgene_gateway.util import current_time_stamp
+from cellxgene_gateway import env
+from cellxgene_gateway import util
+
+logger = logging.getLogger(__name__)
class PruneProcessCache:
def __init__(self, cache):
self.cache = cache
- self.expire_seconds = 3600 if ttl is None else int(ttl)
+ self.expire_seconds = 3600 if env.ttl is None else int(env.ttl)
def __call__(self):
while True:
@@ -25,7 +27,7 @@ class PruneProcessCache:
self.prune()
def prune(self):
- timestamp = current_time_stamp()
+ timestamp = util.current_time_stamp()
cutoff = timestamp - self.expire_seconds
processes_to_delete = [
p for p in self.cache.entry_list if p.timestamp < cutoff
@@ -33,9 +35,9 @@ class PruneProcessCache:
processes_to_keep = [
p for p in self.cache.entry_list if not p.timestamp < cutoff
]
- logger = logging.getLogger("cellxgene_gateway")
+
logger.debug(
- f"Cutoff {cutoff} = timestamp {timestamp} - expire seconds {self.expire_seconds} , keeping {processes_to_keep}"
+ f"Cutoff {cutoff} = timestamp {timestamp} - expire seconds {self.expire_seconds} , keeping {processes_to_keep}, pruning {processes_to_delete}"
)
for process in processes_to_delete:
diff --git a/tests/test_cache_entry.py b/tests/test_cache_entry.py
index d2c80a0..5a2e56e 100644
--- a/tests/test_cache_entry.py
+++ b/tests/test_cache_entry.py
@@ -1,11 +1,19 @@
import unittest
+from flask import Flask
from cellxgene_gateway.cache_entry import CacheEntry, CacheEntryStatus
from cellxgene_gateway.cache_key import CacheKey
+from cellxgene_gateway.gateway import app
key = CacheKey("czi/pbmc3k.h5ad", "pbmc3k.h5ad", "tmp.csv")
class TestRenderEntry(unittest.TestCase):
+ def setUp(self):
+ self.app = app
+ self.app_context = self.app.test_request_context()
+ self.app_context.push()
+ self.client = self.app.test_client()
+
def test_GIVEN_key_and_port_THEN_returns_loading_CacheEntry(self):
entry = CacheEntry.for_key("some-key", 1)
self.assertEqual(entry.status, CacheEntryStatus.loading)
@@ -14,16 +22,14 @@ class TestRenderEntry(unittest.TestCase):
actual = CacheEntry.for_key(key, 8000).rewrite_text_content(
"src:url(/static/assets/"
)
- expected = (
- "src:url(http://localhost:5005/view/czi/pbmc3k.h5ad/static/assets/"
- )
+ expected = "src:url(/view/czi/pbmc3k.h5ad/static/assets/"
self.assertEqual(actual, expected)
def test_GIVEN_absolute_src_THEN_include_path(self):
actual = CacheEntry.for_key(key, 8000).rewrite_text_content(
''
)
- expected = ''
+ expected = ''
self.assertEqual(actual, expected)