Skip to content

Commit

Permalink
Merge pull request #474 from will-moore/script_failure_handling
Browse files Browse the repository at this point in the history
Detect and display non-zero returncode from scripts
  • Loading branch information
knabar authored Oct 19, 2023
2 parents 763bbe1 + 760da8e commit 3a5d88d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -240,22 +240,9 @@
<img alt="Running Script" src="{% static "webgateway/img/spinner.gif" %}" />

{% else %}
{% if j.error %}
<div class='script_error' title="{{ j.error }}">
{% if j.returncode and j.returncode > 0 %}
<div class='script_error' title="Script failed. Please see error logs">
<img alt="Failed to run script properly" src="{% static "webgateway/img/failed.png" %}" />


{% comment %}
<!-- Don't allow submitting now. TODO: launch submit page -->
<img src="{% static "webclient/image/info16.png" %}"/>
<input type='submit' title="Send Error as Feeback to the OME team" jobKey="{{ j.key }}"
{% if j.error_sent %}
value='Thank you' disabled='true'
{% else %}
value='Submit Feedback'
{% endif %} />
{% endcomment %}

</div>
{% else %}
<img alt="Success" src="{% static "webgateway/img/success.png" %}" />
Expand Down
20 changes: 18 additions & 2 deletions omeroweb/webclient/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3524,6 +3524,13 @@ 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):
Expand Down Expand Up @@ -3799,14 +3806,23 @@ 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",
"returncode": cb.returncode,
}
if cb.returncode != 0:
kwargs["Message"] = (
f"Script exited with failure."
f" (returncode={ cb.returncode })"
)
update_callback(request, cbString, **kwargs)
new_results.append(cbString)
except Exception:
update_callback(
Expand Down

0 comments on commit 3a5d88d

Please sign in to comment.