Commit 2b259ab6 authored by Alok Saldanha's avatar Alok Saldanha
Browse files

#2 added a way to relaunch a cellxgene server

parent a6c94567
......@@ -30,7 +30,7 @@ class BackendCache:
def check_entry(self, dataset):
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:
return None
......@@ -61,3 +61,7 @@ class BackendCache:
time.sleep(1) # Automatic refresh is too fast, needs a second to pause
return entry
def prune(self, process):
self.entry_list.remove(process)
process.terminate()
......@@ -73,6 +73,15 @@ class CacheEntry:
else:
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):
dataset = self.dataset
......
......@@ -18,6 +18,7 @@ from flask import (
render_template,
request,
send_from_directory,
url_for,
)
from flask_api import status
from werkzeug import secure_filename
......@@ -187,20 +188,18 @@ def do_GET_status():
"cache_status.html", entry_list=cache.entry_list
)
pruner = PruneProcessCache(cache)
@app.route("/prune/<path:path>", methods=["DELETE"])
def do_prune(path):
@app.route("/relaunch/<path:path>", methods=["GET"])
def do_relaunch(path):
dataset = get_dataset(path)
match = cache.check_entry(dataset)
if match is None:
return "not found"
else:
pruner.prune(match)
return "success"
if not match is None:
match.terminate()
return redirect(url_for('view', path=path), code=301)
def main():
env.validate()
pruner = PruneProcessCache(cache)
background_thread = Thread(target=pruner)
background_thread.start()
......
......@@ -19,15 +19,6 @@ class PruneProcessCache:
def __init__(self, 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):
while True:
time.sleep(60)
......@@ -42,7 +33,7 @@ class PruneProcessCache:
for process in processes_to_delete:
try:
self.prune(process)
cache.prune(process)
except Exception as detail:
print('failed to prune process:', detail)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment