diff --git a/bopytex/scheduler.py b/bopytex/scheduler.py index 7ae6c9a..34b68b7 100644 --- a/bopytex/scheduler.py +++ b/bopytex/scheduler.py @@ -19,6 +19,14 @@ class Scheduler: def tasks(self): return self._tasks + @property + def doable_tasks(self): + return [ + task + for task in self.tasks + if not task.deps or all([d in self.done for d in task.deps]) + ] + @property def all_deps(self): return {d for task in self.tasks for d in task.deps} diff --git a/test/test_scheduler.py b/test/test_scheduler.py index c3cf44a..cca528b 100644 --- a/test/test_scheduler.py +++ b/test/test_scheduler.py @@ -31,7 +31,9 @@ def test_schedule_dispatch(): def test_schedule_one_task(): scheduler = Scheduler(actions) - scheduler.append([Task(action="DO", args={}, deps=[], output="end")]) + tasks = [Task(action="DO", args={}, deps=[], output="end")] + scheduler.append(tasks) + assert scheduler.doable_tasks == tasks result = scheduler.next() assert result == "[] - {} - end - done" assert scheduler.tasks == [] @@ -54,7 +56,8 @@ def test_schedule_multiple_tasks(): t3 = Task(action="DO", args={"task": "three"}, deps=[], output="three") scheduler.append([t1, t2, t3]) - assert scheduler.is_finishable() == True + assert scheduler.doable_tasks == [t1, t2, t3] + assert scheduler.is_finishable() result = scheduler.next() assert result == "[] - {'task': 'one'} - one - done" @@ -79,17 +82,20 @@ def test_schedule_multiple_tasks_with_dependencies(): t3 = Task(action="DO", args={"task": "three"}, deps=[], output="three") scheduler.append([t1, t2, t3]) - assert scheduler.is_finishable() == True + assert scheduler.doable_tasks == [t3] + assert scheduler.is_finishable() result = scheduler.next() assert result == "[] - {'task': 'three'} - three - done" assert scheduler.tasks == [t1, t2] assert scheduler.done == ["three"] + assert scheduler.doable_tasks == [t1] result = scheduler.next() assert result == "['three'] - {'task': 'one'} - one - done" assert scheduler.tasks == [t2] assert scheduler.done == ["three", "one"] + assert scheduler.doable_tasks == [t2] result = scheduler.next() assert result == "['one'] - {'task': 'two'} - two - done" @@ -110,8 +116,10 @@ def test_schedule_multiple_tasks_with_undoable_dependencies(): t2 = Task(action="DO", args={"task": "two"}, deps=[], output="two") scheduler.append([t1, t2]) - assert scheduler.is_finishable() == False + assert scheduler.doable_tasks == [t2] + assert not scheduler.is_finishable() scheduler.run() assert scheduler.tasks == [t1] assert scheduler.done == ["two"] + assert scheduler.doable_tasks == []