diff --git a/crc/services/workflow_service.py b/crc/services/workflow_service.py index f47942b5..3d70463e 100644 --- a/crc/services/workflow_service.py +++ b/crc/services/workflow_service.py @@ -98,15 +98,18 @@ class WorkflowService(object): def do_waiting(): records = db.session.query(WorkflowModel).filter(WorkflowModel.status==WorkflowStatus.waiting).all() for workflow_model in records: - # fixme: Try catch with a very explicit error about the study, workflow and task that failed. try: app.logger.info('Processing workflow %s' % workflow_model.id) processor = WorkflowProcessor(workflow_model) processor.bpmn_workflow.refresh_waiting_tasks() processor.bpmn_workflow.do_engine_steps() processor.save() - except: - app.logger.error('Failed to process workflow') + except Exception as e: + app.logger.error(f"Error running waiting task for workflow #%i (%s) for study #%i. %s" % + (workflow_model.id, + workflow_model.workflow_spec.name, + workflow_model.study_id, + str(e))) @staticmethod @timeit diff --git a/tests/data/timer_event_error/timer_event_error.bpmn b/tests/data/timer_event_error/timer_event_error.bpmn new file mode 100644 index 00000000..4c1f3217 --- /dev/null +++ b/tests/data/timer_event_error/timer_event_error.bpmn @@ -0,0 +1,76 @@ + + + + + Flow_1pahvlr + + + Flow_1pahvlr + Flow_1pvkgnu + + + Flow_1pvkgnu + Flow_1ekgt3x + + + Flow_1ekgt3x + + + + + + + Flow_05lcpdf + # Tries to burp, failes. +my_burp = non_existent_burp_variable + + + Flow_05lcpdf + + timedelta(seconds=.25) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/test_wait_event.py b/tests/test_wait_event.py index dbe4ba13..a30a127b 100644 --- a/tests/test_wait_event.py +++ b/tests/test_wait_event.py @@ -1,13 +1,13 @@ import json import time -from crc.services.workflow_processor import WorkflowProcessor from tests.base_test import BaseTest from crc.models.workflow import WorkflowStatus, WorkflowModel from crc import db from crc.api.common import ApiError from crc.models.task_event import TaskEventModel, TaskEventSchema from crc.services.workflow_service import WorkflowService +from crc.services.workflow_processor import WorkflowProcessor class TestTimerEvent(BaseTest): @@ -28,3 +28,19 @@ class TestTimerEvent(BaseTest): wf = db.session.query(WorkflowModel).filter(WorkflowModel.id == workflow.id).first() self.assertTrue(wf.status != WorkflowStatus.waiting) + def test_waiting_event_error(self): + workflow = self.create_workflow('timer_event_error') + processor = WorkflowProcessor(workflow) + processor.do_engine_steps() + processor.save() + time.sleep(.3) # our timer is at .25 sec so we have to wait for it + # get done waiting + wf = db.session.query(WorkflowModel).filter(WorkflowModel.id == workflow.id).first() + self.assertTrue(wf.status == WorkflowStatus.waiting) + with self.assertLogs('crc', level='ERROR') as cm: + WorkflowService.do_waiting() + self.assertEqual(1, len(cm.output)) + self.assertRegexpMatches(cm.output[0], "workflow #1") + self.assertRegexpMatches(cm.output[0], "study #1") + + self.assertTrue(wf.status == WorkflowStatus.waiting)