@@ -118,7 +118,7 @@ def run(self, **kwargs):
118118 return self .status
119119 self .outputs = self ._run (** kwargs )
120120 _logger .info (f"Job { self .__class__ } complete" )
121- except BaseException :
121+ except Exception :
122122 _logger .error (traceback .format_exc ())
123123 _logger .info (f"Job { self .__class__ } errored" )
124124 self .status = - 1
@@ -410,7 +410,7 @@ def create_alyx_tasks(self, rerun__status__in=None):
410410 tasks_alyx = []
411411 # creates all the tasks by iterating through the ordered dict
412412 for k , t in self .tasks .items ():
413- # get the parents alyx ids to reference in the database
413+ # get the parents' alyx ids to reference in the database
414414 if len (t .parents ):
415415 pnames = [p .name for p in t .parents ]
416416 parents_ids = [ta ['id' ] for ta in tasks_alyx if ta ['name' ] in pnames ]
@@ -492,10 +492,10 @@ def run_alyx_task(tdict=None, session_path=None, one=None, job_deck=None,
492492 :return:
493493 """
494494 registered_dsets = []
495+ # here we need to check parents' status, get the job_deck if not available
496+ if not job_deck :
497+ job_deck = one .alyx .rest ('tasks' , 'list' , session = tdict ['session' ], no_cache = True )
495498 if len (tdict ['parents' ]):
496- # here we need to check parents status, get the job_deck if not available
497- if not job_deck :
498- job_deck = one .alyx .rest ('tasks' , 'list' , session = tdict ['session' ], no_cache = True )
499499 # check the dependencies
500500 parent_tasks = filter (lambda x : x ['id' ] in tdict ['parents' ], job_deck )
501501 parent_statuses = [j ['status' ] for j in parent_tasks ]
@@ -526,7 +526,7 @@ def run_alyx_task(tdict=None, session_path=None, one=None, job_deck=None,
526526 else :
527527 try :
528528 registered_dsets = task .register_datasets (one = one , max_md5_size = max_md5_size )
529- except BaseException :
529+ except Exception :
530530 _logger .error (traceback .format_exc ())
531531 patch_data ['status' ] = 'Errored'
532532 patch_data ['status' ] = 'Complete'
@@ -541,5 +541,15 @@ def run_alyx_task(tdict=None, session_path=None, one=None, job_deck=None,
541541 patch_data ['status' ] = 'Incomplete'
542542 # update task status on Alyx
543543 t = one .alyx .rest ('tasks' , 'partial_update' , id = tdict ['id' ], data = patch_data )
544+ # check for dependent held tasks
545+ # NB: Assumes dependent tasks are all part of the same session!
546+ next (x for x in job_deck if x ['id' ] == t ['id' ])['status' ] = t ['status' ] # Update status in job deck
547+ dependent_tasks = filter (lambda x : t ['id' ] in x ['parents' ] and x ['status' ] == 'Held' , job_deck )
548+ for d in dependent_tasks :
549+ assert d ['id' ] != t ['id' ], 'task its own parent'
550+ # if all their parent tasks now complete, set to waiting
551+ parent_status = [next (x ['status' ] for x in job_deck if x ['id' ] == y ) for y in d ['parents' ]]
552+ if all (x == 'Complete' for x in parent_status ):
553+ one .alyx .rest ('tasks' , 'partial_update' , id = d ['id' ], data = {'status' : 'Waiting' })
544554 task .cleanUp ()
545555 return t , registered_dsets
0 commit comments