Fixed broken error handling for long-running tasks

This commit is contained in:
Joel Collins 2019-01-28 17:49:44 +00:00
parent e3a27b024a
commit a11d2145d9
5 changed files with 45 additions and 4 deletions

View file

@ -72,5 +72,24 @@ class LongRunningAPI(MicroscopeViewPlugin):
task = self.microscope.task.start(self.plugin.long_running, time_to_run)
return jsonify(task.state), 202
except TaskDeniedException:
return abort(409)
class SomeExceptionAPI(MicroscopeViewPlugin):
"""
An example API plugin that uses a long-running but broken plugin method.
"""
def post(self):
"""
Method to call when an HTTP POST request is made.
"""
# Get payload JSON
payload = JsonPayload(request)
# Attach the long-running method as a microscope task
try:
task = self.microscope.task.start(self.plugin.some_exception)
return jsonify(task.state), 202
except TaskDeniedException:
return abort(409)