From 59bf136864021435a9ee67134fccd7503a08a24f Mon Sep 17 00:00:00 2001 From: Dan Date: Sun, 23 Apr 2023 12:22:43 -0400 Subject: [PATCH] * Was doing things a bit out of order - so we weren't always displaying messages as we should have on the interstitial page. * Do a better job of catching all the error messages when they happen. --- .../routes/tasks_controller.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/routes/tasks_controller.py b/spiffworkflow-backend/src/spiffworkflow_backend/routes/tasks_controller.py index 49860394..8dd8d05d 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/routes/tasks_controller.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/routes/tasks_controller.py @@ -406,16 +406,25 @@ def _interstitial_stream(process_instance_id: int) -> Generator[str, Optional[st yield f"data: {current_app.json.dumps(task)} \n\n" last_task = spiff_task try: - processor.do_engine_steps(execution_strategy_name="run_until_user_message") processor.do_engine_steps(execution_strategy_name="one_at_a_time") + processor.do_engine_steps(execution_strategy_name="run_until_user_message") + processor.save() # Fixme - maybe find a way not to do this on every loop? except WorkflowTaskException as wfe: api_error = ApiError.from_workflow_exception( "engine_steps_error", "Failed complete an automated task.", exp=wfe ) yield f"data: {current_app.json.dumps(api_error)} \n\n" + except Exception as e: + api_error = ApiError( + error_code="engine_steps_error", + message=f"Failed complete an automated task. Error was: {str(e)}", + status_code=400, + ) + yield f"data: {current_app.json.dumps(api_error)} \n\n" + + # Note, this has to be done in case someone leaves the page, # which can otherwise cancel this function and leave completed tasks un-registered. - processor.save() # Fixme - maybe find a way not to do this on every loop? spiff_task = processor.next_task() # Always provide some response, in the event no instructions were provided.