Skip to content

Commit

Permalink
fix double timeline status for sync events, cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
mikkonie committed Oct 31, 2022
1 parent 23013f0 commit 188cc42
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
4 changes: 2 additions & 2 deletions samplesheets/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
23 changes: 13 additions & 10 deletions taskflowbackend/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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)')
Expand All @@ -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:
Expand All @@ -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(
Expand Down

0 comments on commit 188cc42

Please sign in to comment.