Skip to content

Commit 2c15425

Browse files
committed
graph runner: prune away tasks which cannot be fullfilled
1 parent 06576a5 commit 2c15425

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

MC/bin/o2_dpg_workflow_runner.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,8 +322,28 @@ def task_matches_labels(t):
322322
# helper lookup
323323
tasknametoid = { t['name']:i for i, t in enumerate(workflowspec['stages'],0) }
324324

325+
# check if a task can be run at all
326+
# or not due to missing requirements
327+
def canBeDone(t,cache={}):
328+
ok = True
329+
c = cache.get(t['name'])
330+
if c != None:
331+
return c
332+
for r in t['needs']:
333+
taskid = tasknametoid.get(r)
334+
if taskid != None:
335+
if not canBeDone(workflowspec['stages'][taskid], cache):
336+
ok = False
337+
break
338+
else:
339+
ok = False
340+
break
341+
cache[t['name']] = ok
342+
return ok
343+
344+
okcache = {}
325345
# build full target list
326-
full_target_list = [ t for t in workflowspec['stages'] if task_matches(t['name']) and task_matches_labels(t) ]
346+
full_target_list = [ t for t in workflowspec['stages'] if task_matches(t['name']) and task_matches_labels(t) and canBeDone(t,okcache) ]
327347
full_target_name_list = [ t['name'] for t in full_target_list ]
328348

329349
# build full dependency list for a task t

0 commit comments

Comments
 (0)