mirror of
https://github.com/Novartis/cellxgene-gateway.git
synced 2026-10-10 07:10:56 +08:00
#2 added a way to relaunch a cellxgene server
This commit is contained in:
@@ -30,7 +30,7 @@ class BackendCache:
|
|||||||
|
|
||||||
def check_entry(self, dataset):
|
def check_entry(self, dataset):
|
||||||
contents = self.entry_list
|
contents = self.entry_list
|
||||||
matches = [c for c in contents if c.dataset == dataset]
|
matches = [c for c in contents if c.dataset == dataset and c.status != "terminated"]
|
||||||
|
|
||||||
if len(matches) == 0:
|
if len(matches) == 0:
|
||||||
return None
|
return None
|
||||||
@@ -61,3 +61,7 @@ class BackendCache:
|
|||||||
time.sleep(1) # Automatic refresh is too fast, needs a second to pause
|
time.sleep(1) # Automatic refresh is too fast, needs a second to pause
|
||||||
|
|
||||||
return entry
|
return entry
|
||||||
|
|
||||||
|
def prune(self, process):
|
||||||
|
self.entry_list.remove(process)
|
||||||
|
process.terminate()
|
||||||
|
|||||||
@@ -73,6 +73,15 @@ class CacheEntry:
|
|||||||
else:
|
else:
|
||||||
self.all_output += output
|
self.all_output += output
|
||||||
|
|
||||||
|
def terminate(self, process):
|
||||||
|
if pid != None and self.status != "terminated":
|
||||||
|
p = psutil.Process(pid)
|
||||||
|
p.terminate()
|
||||||
|
p = psutil.Process(pid + 2)
|
||||||
|
p.terminate()
|
||||||
|
self.status = "terminated"
|
||||||
|
|
||||||
|
|
||||||
def serve_content(self, path):
|
def serve_content(self, path):
|
||||||
dataset = self.dataset
|
dataset = self.dataset
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ from flask import (
|
|||||||
render_template,
|
render_template,
|
||||||
request,
|
request,
|
||||||
send_from_directory,
|
send_from_directory,
|
||||||
|
url_for,
|
||||||
)
|
)
|
||||||
from flask_api import status
|
from flask_api import status
|
||||||
from werkzeug import secure_filename
|
from werkzeug import secure_filename
|
||||||
@@ -187,20 +188,18 @@ def do_GET_status():
|
|||||||
"cache_status.html", entry_list=cache.entry_list
|
"cache_status.html", entry_list=cache.entry_list
|
||||||
)
|
)
|
||||||
|
|
||||||
pruner = PruneProcessCache(cache)
|
|
||||||
|
|
||||||
@app.route("/prune/<path:path>", methods=["DELETE"])
|
@app.route("/relaunch/<path:path>", methods=["GET"])
|
||||||
def do_prune(path):
|
def do_relaunch(path):
|
||||||
dataset = get_dataset(path)
|
dataset = get_dataset(path)
|
||||||
match = cache.check_entry(dataset)
|
match = cache.check_entry(dataset)
|
||||||
if match is None:
|
if not match is None:
|
||||||
return "not found"
|
match.terminate()
|
||||||
else:
|
return redirect(url_for('view', path=path), code=301)
|
||||||
pruner.prune(match)
|
|
||||||
return "success"
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
env.validate()
|
env.validate()
|
||||||
|
pruner = PruneProcessCache(cache)
|
||||||
background_thread = Thread(target=pruner)
|
background_thread = Thread(target=pruner)
|
||||||
background_thread.start()
|
background_thread.start()
|
||||||
|
|
||||||
|
|||||||
@@ -19,15 +19,6 @@ class PruneProcessCache:
|
|||||||
def __init__(self, cache):
|
def __init__(self, cache):
|
||||||
self.cache = cache
|
self.cache = cache
|
||||||
|
|
||||||
def prune(self, process):
|
|
||||||
self.cache.entry_list.remove(process)
|
|
||||||
pid = process.pid
|
|
||||||
if pid != None:
|
|
||||||
p = psutil.Process(pid)
|
|
||||||
p.terminate()
|
|
||||||
p = psutil.Process(pid + 2)
|
|
||||||
p.terminate()
|
|
||||||
|
|
||||||
def __call__(self):
|
def __call__(self):
|
||||||
while True:
|
while True:
|
||||||
time.sleep(60)
|
time.sleep(60)
|
||||||
@@ -42,7 +33,7 @@ class PruneProcessCache:
|
|||||||
|
|
||||||
for process in processes_to_delete:
|
for process in processes_to_delete:
|
||||||
try:
|
try:
|
||||||
self.prune(process)
|
cache.prune(process)
|
||||||
except Exception as detail:
|
except Exception as detail:
|
||||||
print('failed to prune process:', detail)
|
print('failed to prune process:', detail)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user