From 803f18c7b1b312c4ec2d8026a1df8a869045312c Mon Sep 17 00:00:00 2001 From: William Moore Date: Wed, 24 May 2023 12:15:33 +0100 Subject: [PATCH 1/9] Detect and display non-zero returncode from scripts --- .../activities/activitiesContent.html | 17 ++-------------- omeroweb/webclient/views.py | 20 +++++++++++++++++-- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/omeroweb/webclient/templates/webclient/activities/activitiesContent.html b/omeroweb/webclient/templates/webclient/activities/activitiesContent.html index 22944801f8..6982ef6a9a 100644 --- a/omeroweb/webclient/templates/webclient/activities/activitiesContent.html +++ b/omeroweb/webclient/templates/webclient/activities/activitiesContent.html @@ -230,7 +230,7 @@ - + {% ifequal j.job_type "script" %} @@ -241,21 +241,8 @@ {% else %} {% if j.error %} -
+
Failed to run script properly - - - {% comment %} - - - - {% endcomment %} -
{% else %} Success diff --git a/omeroweb/webclient/views.py b/omeroweb/webclient/views.py index 82da8ce467..38ada32756 100755 --- a/omeroweb/webclient/views.py +++ b/omeroweb/webclient/views.py @@ -3522,6 +3522,14 @@ def update_callback(request, cbString, **kwargs): request.session["callback"][cbString][key] = value +# Subclass to handle returncode +class ScriptsCallback(omero.scripts.ProcessCallbackI): + + def processFinished(self, returncode, current=None): + super().processFinished(returncode, current) + self.returncode = returncode + + @login_required() @render_response() def activities(request, conn=None, **kwargs): @@ -3797,14 +3805,22 @@ def activities(request, conn=None, **kwargs): error=1, ) continue - cb = omero.scripts.ProcessCallbackI(conn.c, proc) + cb = ScriptsCallback(conn.c, proc) # check if we get something back from the handle... if cb.block(0): # ms. cb.close() try: # we can only retrieve this ONCE - must save results results = proc.getResults(0, conn.SERVICE_OPTS) - update_callback(request, cbString, status="finished") + kwargs = { + "status": ("finished" if cb.returncode == 0 else "failed"), + "failure": cb.returncode, + } + if cb.returncode != 0: + # This 'error' shows failure icon + kwargs["error"] = 1 + kwargs["Message"] = "Script failed with Exception" + update_callback(request, cbString, **kwargs) new_results.append(cbString) except Exception: update_callback( From bd9f57defe40c5aab392a16d5e1372dec084c935 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 24 May 2023 11:41:50 +0000 Subject: [PATCH 2/9] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- omeroweb/webclient/views.py | 1 - 1 file changed, 1 deletion(-) diff --git a/omeroweb/webclient/views.py b/omeroweb/webclient/views.py index 38ada32756..502fd79268 100755 --- a/omeroweb/webclient/views.py +++ b/omeroweb/webclient/views.py @@ -3524,7 +3524,6 @@ def update_callback(request, cbString, **kwargs): # Subclass to handle returncode class ScriptsCallback(omero.scripts.ProcessCallbackI): - def processFinished(self, returncode, current=None): super().processFinished(returncode, current) self.returncode = returncode From f5384a2504c86ebb3af9481ef7e11c5688e200d9 Mon Sep 17 00:00:00 2001 From: William Moore Date: Wed, 24 May 2023 13:00:58 +0100 Subject: [PATCH 3/9] Add returncode to error message --- omeroweb/webclient/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/omeroweb/webclient/views.py b/omeroweb/webclient/views.py index 502fd79268..8dddc8304c 100755 --- a/omeroweb/webclient/views.py +++ b/omeroweb/webclient/views.py @@ -3818,7 +3818,7 @@ def activities(request, conn=None, **kwargs): if cb.returncode != 0: # This 'error' shows failure icon kwargs["error"] = 1 - kwargs["Message"] = "Script failed with Exception" + kwargs["Message"] = f"Script exited with failure. (returncode={ cb.returncode })" update_callback(request, cbString, **kwargs) new_results.append(cbString) except Exception: From f4c0fcd66017b14f5a3e7de035107b48e090356e Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 24 May 2023 12:02:11 +0000 Subject: [PATCH 4/9] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- omeroweb/webclient/views.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/omeroweb/webclient/views.py b/omeroweb/webclient/views.py index 8dddc8304c..88d327a651 100755 --- a/omeroweb/webclient/views.py +++ b/omeroweb/webclient/views.py @@ -3818,7 +3818,9 @@ def activities(request, conn=None, **kwargs): if cb.returncode != 0: # This 'error' shows failure icon kwargs["error"] = 1 - kwargs["Message"] = f"Script exited with failure. (returncode={ cb.returncode })" + kwargs[ + "Message" + ] = f"Script exited with failure. (returncode={ cb.returncode })" update_callback(request, cbString, **kwargs) new_results.append(cbString) except Exception: From 18799562d77cb62775463bf9561f6d333f22c9d2 Mon Sep 17 00:00:00 2001 From: William Moore Date: Wed, 24 May 2023 13:31:52 +0100 Subject: [PATCH 5/9] flake8 fix --- omeroweb/webclient/views.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/omeroweb/webclient/views.py b/omeroweb/webclient/views.py index 88d327a651..d18a82d6aa 100755 --- a/omeroweb/webclient/views.py +++ b/omeroweb/webclient/views.py @@ -3820,7 +3820,8 @@ def activities(request, conn=None, **kwargs): kwargs["error"] = 1 kwargs[ "Message" - ] = f"Script exited with failure. (returncode={ cb.returncode })" + ] = (f"Script exited with failure." + f" (returncode={ cb.returncode })") update_callback(request, cbString, **kwargs) new_results.append(cbString) except Exception: From 8081fa72c1453a530aafb403d62c92a0e81835d5 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 24 May 2023 12:32:13 +0000 Subject: [PATCH 6/9] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- omeroweb/webclient/views.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/omeroweb/webclient/views.py b/omeroweb/webclient/views.py index d18a82d6aa..81c51a4689 100755 --- a/omeroweb/webclient/views.py +++ b/omeroweb/webclient/views.py @@ -3818,10 +3818,10 @@ def activities(request, conn=None, **kwargs): if cb.returncode != 0: # This 'error' shows failure icon kwargs["error"] = 1 - kwargs[ - "Message" - ] = (f"Script exited with failure." - f" (returncode={ cb.returncode })") + kwargs["Message"] = ( + f"Script exited with failure." + f" (returncode={ cb.returncode })" + ) update_callback(request, cbString, **kwargs) new_results.append(cbString) except Exception: From c9a586dfb1f3de226f0726ff501dbab6919ee227 Mon Sep 17 00:00:00 2001 From: William Moore Date: Mon, 29 May 2023 09:07:22 +0100 Subject: [PATCH 7/9] Revert Comment change to avoid merge conflict --- .../templates/webclient/activities/activitiesContent.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/omeroweb/webclient/templates/webclient/activities/activitiesContent.html b/omeroweb/webclient/templates/webclient/activities/activitiesContent.html index 6982ef6a9a..4ab3a14b03 100644 --- a/omeroweb/webclient/templates/webclient/activities/activitiesContent.html +++ b/omeroweb/webclient/templates/webclient/activities/activitiesContent.html @@ -230,7 +230,7 @@ - + {% ifequal j.job_type "script" %} From 659d4c5b48a37d85f446a10d4eb901405b72595b Mon Sep 17 00:00:00 2001 From: William Moore Date: Tue, 10 Oct 2023 15:32:53 +0100 Subject: [PATCH 8/9] Always use status:'finished' when done, even if error --- omeroweb/webclient/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/omeroweb/webclient/views.py b/omeroweb/webclient/views.py index 3492463b77..1144dfff06 100755 --- a/omeroweb/webclient/views.py +++ b/omeroweb/webclient/views.py @@ -3814,7 +3814,7 @@ def activities(request, conn=None, **kwargs): # we can only retrieve this ONCE - must save results results = proc.getResults(0, conn.SERVICE_OPTS) kwargs = { - "status": ("finished" if cb.returncode == 0 else "failed"), + "status": "finished", "failure": cb.returncode, } if cb.returncode != 0: From 760da8ed348be1ccc3d639a3fdfd5cd6dda8c8a1 Mon Sep 17 00:00:00 2001 From: William Moore Date: Wed, 18 Oct 2023 11:11:00 +0100 Subject: [PATCH 9/9] Use 'returncode' instead of 'failure' and 'error' --- .../templates/webclient/activities/activitiesContent.html | 2 +- omeroweb/webclient/views.py | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/omeroweb/webclient/templates/webclient/activities/activitiesContent.html b/omeroweb/webclient/templates/webclient/activities/activitiesContent.html index a9f4d8c8b0..4365250ef4 100644 --- a/omeroweb/webclient/templates/webclient/activities/activitiesContent.html +++ b/omeroweb/webclient/templates/webclient/activities/activitiesContent.html @@ -240,7 +240,7 @@ Running Script {% else %} - {% if j.error %} + {% if j.returncode and j.returncode > 0 %}
Failed to run script properly
diff --git a/omeroweb/webclient/views.py b/omeroweb/webclient/views.py index 1144dfff06..9e84198303 100755 --- a/omeroweb/webclient/views.py +++ b/omeroweb/webclient/views.py @@ -3815,11 +3815,9 @@ def activities(request, conn=None, **kwargs): results = proc.getResults(0, conn.SERVICE_OPTS) kwargs = { "status": "finished", - "failure": cb.returncode, + "returncode": cb.returncode, } if cb.returncode != 0: - # This 'error' shows failure icon - kwargs["error"] = 1 kwargs["Message"] = ( f"Script exited with failure." f" (returncode={ cb.returncode })"