From 188cc42eda4a937aff05c6da8f376f31766efe96 Mon Sep 17 00:00:00 2001 From: Mikko Nieminen Date: Mon, 31 Oct 2022 18:35:01 +0100 Subject: [PATCH] fix double timeline status for sync events, cleanup --- samplesheets/views.py | 4 ++-- taskflowbackend/api.py | 23 +++++++++++++---------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/samplesheets/views.py b/samplesheets/views.py index 02cfcc21..3f684161 100644 --- a/samplesheets/views.py +++ b/samplesheets/views.py @@ -2334,8 +2334,8 @@ def form_valid(self, request, *args, **kwargs): tl_event.set_status('FAILED', str(ex)) obj.status = 'FAILED' obj.save() - # if settings.DEBUG: - # raise ex + if settings.DEBUG: + raise ex messages.error( self.request, 'Accepting iRODS data request "{}" failed: {}'.format( diff --git a/taskflowbackend/api.py b/taskflowbackend/api.py index 2c4fe2fe..b4eed776 100644 --- a/taskflowbackend/api.py +++ b/taskflowbackend/api.py @@ -43,14 +43,15 @@ class FlowSubmitException(Exception): def _raise_flow_exception(cls, ex_msg, tl_event=None, zone=None): """ Handle and raise exception with flow building or execution. Updates an - associated timeline event if present, as well as a landing zone if - provided in the flow data. + associated timeline event if present and flow is in async mode. Also + updates landing zone status if zone is provided. :param ex_msg: Exception message (string) :param tl_event: Timeline event or None :zone: LandingZone object or None :raise: FlowSubmitException """ + # TODO: Only set status if async mode if tl_event: tl_event.set_status('FAILED', ex_msg) # HACK: Update landing zone @@ -114,18 +115,21 @@ def run_flow( :param project: Project object :param force_fail: Force failure (boolean, for testing) :param async_mode: Submit in async mode (boolean, default=False) - :param tl_event: Timeline ProjectEvent object or None + :param tl_event: Timeline ProjectEvent object or None. Event status will + be updated if the flow is run in async mode. :return: Dict """ flow_result = None ex_msg = None coordinator = None lock = None - # HACK: Get zone if present in flow + # Get zone if present in flow zone_uuid = flow.flow_data.get('zone_uuid') zone = None if zone_uuid: zone = LandingZone.objects.filter(sodar_uuid=zone_uuid).first() + # Provide tl_event for exceptions only if async mode + tl_event_ex = tl_event if async_mode else None # Acquire lock if needed if flow.require_lock: @@ -134,7 +138,7 @@ def run_flow( if not coordinator: cls._raise_flow_exception( LOCK_FAIL_MSG + ': Failed to retrieve lock coordinator', - tl_event, + tl_event_ex, zone, ) else: @@ -144,7 +148,7 @@ def run_flow( lock_api.acquire(lock) except Exception as ex: cls._raise_flow_exception( - LOCK_FAIL_MSG + ': {}'.format(ex), tl_event, zone + LOCK_FAIL_MSG + ': {}'.format(ex), tl_event_ex, zone ) else: logger.info('Lock not required (flow.require_lock=False)') @@ -168,9 +172,8 @@ def run_flow( if flow_result and tl_event and async_mode: tl_event.set_status('OK', 'Async submit OK') # Exception/failure - elif not flow_result: - if not ex_msg: - ex_msg = UNKNOWN_RUN_ERROR + elif not flow_result and not ex_msg: + ex_msg = UNKNOWN_RUN_ERROR # Release lock if acquired if flow.require_lock and lock: @@ -182,7 +185,7 @@ def run_flow( logger.error(ex_msg) # TODO: Isn't this redundant? # NOTE: Not providing zone here since it's handled by flow # TODO: Replace RevertLandingZoneFailTask with a call here? - cls._raise_flow_exception(ex_msg, tl_event, None) + cls._raise_flow_exception(ex_msg, tl_event_ex, None) return flow_result def submit(