diff --git a/cellxgene_gateway/cache_entry.py b/cellxgene_gateway/cache_entry.py index 5dda033..829d3c5 100644 --- a/cellxgene_gateway/cache_entry.py +++ b/cellxgene_gateway/cache_entry.py @@ -6,6 +6,7 @@ # under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES # OR CONDITIONS OF ANY KIND, either express or implied. See the License for # the specific language governing permissions and limitations under the License. +import psutil from flask import make_response, request from requests import get, post, put @@ -73,7 +74,8 @@ class CacheEntry: else: self.all_output += output - def terminate(self, process): + def terminate(self): + pid = self.pid if pid != None and self.status != "terminated": p = psutil.Process(pid) p.terminate() diff --git a/cellxgene_gateway/gateway.py b/cellxgene_gateway/gateway.py index 04e4448..0586655 100644 --- a/cellxgene_gateway/gateway.py +++ b/cellxgene_gateway/gateway.py @@ -48,6 +48,7 @@ def handle_invalid_usage(error): "cellxgene_error.html", extra_scripts=get_extra_scripts(), message=message, + path=error.path ), error.http_status, ) @@ -67,7 +68,11 @@ def handle_invalid_process(error): render_template( "process_error.html", extra_scripts=get_extra_scripts(), - message=message, + message=error.message, + http_status=error.http_status, + stdout=error.stdout, + stderr=error.stderr, + dataset=error.dataset, ), error.http_status, ) @@ -180,7 +185,7 @@ def do_view(path): "loading.html", launchtime=launch_time, all_output=match.all_output ) elif match.status == "error": - raise ProcessException.from_pid_object(match) + raise ProcessException.from_cache_entry(match) @app.route("/cache_status", methods=["GET"]) def do_GET_status(): @@ -195,7 +200,7 @@ def do_relaunch(path): match = cache.check_entry(dataset) if not match is None: match.terminate() - return redirect(url_for('view', path=path), code=301) + return redirect(url_for('do_view', path=path), code=302) def main(): env.validate() diff --git a/cellxgene_gateway/process_exception.py b/cellxgene_gateway/process_exception.py index 5afdb00..a90f35d 100644 --- a/cellxgene_gateway/process_exception.py +++ b/cellxgene_gateway/process_exception.py @@ -9,18 +9,20 @@ class ProcessException(Exception): - def __init__(self, message, stdout, stderr, http_status): + def __init__(self, message, stdout, stderr, http_status, dataset): Exception.__init__(self) self.message = message self.stdout = stdout self.stderr = stderr self.http_status = http_status + self.dataset = dataset @classmethod - def from_pid_object(cls, pid_object): + def from_cache_entry(cls, cache_entry): return cls( - pid_object.message, - pid_object.all_output, - pid_object.stderr, - pid_object.http_status, + cache_entry.message, + cache_entry.all_output, + cache_entry.stderr, + cache_entry.http_status, + cache_entry.dataset, ) diff --git a/cellxgene_gateway/prune_process_cache.py b/cellxgene_gateway/prune_process_cache.py index 6c563ec..1829d51 100644 --- a/cellxgene_gateway/prune_process_cache.py +++ b/cellxgene_gateway/prune_process_cache.py @@ -9,8 +9,6 @@ import time -import psutil - from cellxgene_gateway.util import current_time_stamp from cellxgene_gateway.env import ttl diff --git a/cellxgene_gateway/subprocess_backend.py b/cellxgene_gateway/subprocess_backend.py index 3ee0107..28d3df6 100644 --- a/cellxgene_gateway/subprocess_backend.py +++ b/cellxgene_gateway/subprocess_backend.py @@ -62,7 +62,7 @@ class SubprocessBackend: cache_entry.status = "error" cache_entry.set_error(message, stderr, http_status) - raise ProcessException.from_pid_object(cache_entry) + raise ProcessException.from_cache_entry(cache_entry) else: cache_entry.append_output(output) diff --git a/cellxgene_gateway/templates/cache_status.html b/cellxgene_gateway/templates/cache_status.html index 73ac531..cafaee4 100644 --- a/cellxgene_gateway/templates/cache_status.html +++ b/cellxgene_gateway/templates/cache_status.html @@ -31,7 +31,7 @@