mirror of
https://github.com/Novartis/cellxgene-gateway.git
synced 2026-10-09 00:28:13 +08:00
GH-4 properly reference cache.prune
also added logging
This commit is contained in:
@@ -17,6 +17,7 @@ from cellxgene_gateway.env import ttl
|
|||||||
class PruneProcessCache:
|
class PruneProcessCache:
|
||||||
def __init__(self, cache):
|
def __init__(self, cache):
|
||||||
self.cache = cache
|
self.cache = cache
|
||||||
|
self.expire_seconds = (3600 if ttl is None else int(ttl))
|
||||||
|
|
||||||
def __call__(self):
|
def __call__(self):
|
||||||
while True:
|
while True:
|
||||||
@@ -25,16 +26,14 @@ class PruneProcessCache:
|
|||||||
|
|
||||||
def prune(self):
|
def prune(self):
|
||||||
timestamp = current_time_stamp()
|
timestamp = current_time_stamp()
|
||||||
|
cutoff = timestamp - self.expire_seconds
|
||||||
processes_to_delete = []
|
processes_to_delete = [p for p in self.cache.entry_list if p.timestamp < cutoff]
|
||||||
for p in self.cache.entry_list:
|
processes_to_keep = [p for p in self.cache.entry_list if not p.timestamp < cutoff]
|
||||||
if timestamp - p.timestamp > (3600 if ttl is None else ttl):
|
logging.getLogger("werkzeug").debug(f"Cutoff {cutoff} = timestamp {timestamp} - expire seconds {self.expire_seconds} , keeping {processes_to_keep}")
|
||||||
processes_to_delete.append(p)
|
|
||||||
processes_to_delete
|
|
||||||
|
|
||||||
for process in processes_to_delete:
|
for process in processes_to_delete:
|
||||||
try:
|
try:
|
||||||
cache.prune(process)
|
logging.getLogger("werkzeug").info(f"pruning process {process.pid} ({process.dataset})")
|
||||||
|
self.cache.prune(process)
|
||||||
except Exception:
|
except Exception:
|
||||||
logging.getLogger("werkzeug").exception("failed to prune process")
|
logging.getLogger("werkzeug").exception("failed to prune process {process.pid} ({process.dataset})")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user