From f7f49b3568d807c1a7de60ab4047d8ceeb35321b Mon Sep 17 00:00:00 2001 From: Alok Saldanha Date: Tue, 17 Sep 2019 11:05:22 -0400 Subject: [PATCH] #2 added link to relaunch server on process error page --- cellxgene_gateway/cache_entry.py | 4 ++- cellxgene_gateway/gateway.py | 11 ++++-- cellxgene_gateway/process_exception.py | 14 ++++---- cellxgene_gateway/prune_process_cache.py | 2 -- cellxgene_gateway/subprocess_backend.py | 2 +- cellxgene_gateway/templates/cache_status.html | 16 +++++++-- cellxgene_gateway/templates/index.html | 9 ++--- .../templates/process_error.html | 36 +++++++++++-------- 8 files changed, 60 insertions(+), 34 deletions(-) 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 @@ dataset port launchtime - timestamp + last access status message http_status @@ -43,8 +43,8 @@ {{ entry.pid }} {{ entry.dataset }} {{ entry.port }} - {{ entry.launchtime }} - {{ entry.timestamp }} + {{ entry.launchtime }} + {{ entry.timestamp }} {{ entry.status }} {{ entry.message }} {{ entry.http_status }} @@ -52,5 +52,15 @@ {% endfor %} + diff --git a/cellxgene_gateway/templates/index.html b/cellxgene_gateway/templates/index.html index 56a9cb5..b306108 100644 --- a/cellxgene_gateway/templates/index.html +++ b/cellxgene_gateway/templates/index.html @@ -39,6 +39,11 @@ File Crawler: Allows you to view all uploaded data. +
+ + Cache Status: view status of launched cellxgene servers. +
+

@@ -103,9 +108,5 @@ scp -r pbmc3k.h5ad ec2-user@{{ ip }}:{{ cellxgene_data }}/USER/DATA/
  • Take a look at your data using the file crawler link above
  • - - diff --git a/cellxgene_gateway/templates/process_error.html b/cellxgene_gateway/templates/process_error.html index 1c5d13e..fb8c8bd 100644 --- a/cellxgene_gateway/templates/process_error.html +++ b/cellxgene_gateway/templates/process_error.html @@ -25,19 +25,27 @@
    - -

    {{ message[0] }}

    -

    {{ message[1] }}

    -

    {{ message[2] }}

    -

    {{ message[3] }}

    - - - Please click here to be redirected to the file directory. - -
    - - Please click here to return to the homepage. - -
    +

    Error Details

    + + + + + +
    Message{{ message }}
    Status{{ http_status }}
    Stdout{{ stdout }}
    Stderr{{ stderr }}
    +
    +

    Options

    + Please choose one of the following, or use the back button: + +