Feat: add doable_task to scheduler
This commit is contained in:
parent
dc12a919d0
commit
03482d4b3d
@ -19,6 +19,14 @@ class Scheduler:
|
|||||||
def tasks(self):
|
def tasks(self):
|
||||||
return self._tasks
|
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
|
@property
|
||||||
def all_deps(self):
|
def all_deps(self):
|
||||||
return {d for task in self.tasks for d in task.deps}
|
return {d for task in self.tasks for d in task.deps}
|
||||||
|
@ -31,7 +31,9 @@ def test_schedule_dispatch():
|
|||||||
|
|
||||||
def test_schedule_one_task():
|
def test_schedule_one_task():
|
||||||
scheduler = Scheduler(actions)
|
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()
|
result = scheduler.next()
|
||||||
assert result == "[] - {} - end - done"
|
assert result == "[] - {} - end - done"
|
||||||
assert scheduler.tasks == []
|
assert scheduler.tasks == []
|
||||||
@ -54,7 +56,8 @@ def test_schedule_multiple_tasks():
|
|||||||
t3 = Task(action="DO", args={"task": "three"}, deps=[], output="three")
|
t3 = Task(action="DO", args={"task": "three"}, deps=[], output="three")
|
||||||
scheduler.append([t1, t2, t3])
|
scheduler.append([t1, t2, t3])
|
||||||
|
|
||||||
assert scheduler.is_finishable() == True
|
assert scheduler.doable_tasks == [t1, t2, t3]
|
||||||
|
assert scheduler.is_finishable()
|
||||||
|
|
||||||
result = scheduler.next()
|
result = scheduler.next()
|
||||||
assert result == "[] - {'task': 'one'} - one - done"
|
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")
|
t3 = Task(action="DO", args={"task": "three"}, deps=[], output="three")
|
||||||
scheduler.append([t1, t2, t3])
|
scheduler.append([t1, t2, t3])
|
||||||
|
|
||||||
assert scheduler.is_finishable() == True
|
assert scheduler.doable_tasks == [t3]
|
||||||
|
assert scheduler.is_finishable()
|
||||||
|
|
||||||
result = scheduler.next()
|
result = scheduler.next()
|
||||||
assert result == "[] - {'task': 'three'} - three - done"
|
assert result == "[] - {'task': 'three'} - three - done"
|
||||||
assert scheduler.tasks == [t1, t2]
|
assert scheduler.tasks == [t1, t2]
|
||||||
assert scheduler.done == ["three"]
|
assert scheduler.done == ["three"]
|
||||||
|
assert scheduler.doable_tasks == [t1]
|
||||||
|
|
||||||
result = scheduler.next()
|
result = scheduler.next()
|
||||||
assert result == "['three'] - {'task': 'one'} - one - done"
|
assert result == "['three'] - {'task': 'one'} - one - done"
|
||||||
assert scheduler.tasks == [t2]
|
assert scheduler.tasks == [t2]
|
||||||
assert scheduler.done == ["three", "one"]
|
assert scheduler.done == ["three", "one"]
|
||||||
|
assert scheduler.doable_tasks == [t2]
|
||||||
|
|
||||||
result = scheduler.next()
|
result = scheduler.next()
|
||||||
assert result == "['one'] - {'task': 'two'} - two - done"
|
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")
|
t2 = Task(action="DO", args={"task": "two"}, deps=[], output="two")
|
||||||
scheduler.append([t1, t2])
|
scheduler.append([t1, t2])
|
||||||
|
|
||||||
assert scheduler.is_finishable() == False
|
assert scheduler.doable_tasks == [t2]
|
||||||
|
assert not scheduler.is_finishable()
|
||||||
|
|
||||||
scheduler.run()
|
scheduler.run()
|
||||||
assert scheduler.tasks == [t1]
|
assert scheduler.tasks == [t1]
|
||||||
assert scheduler.done == ["two"]
|
assert scheduler.done == ["two"]
|
||||||
|
assert scheduler.doable_tasks == []
|
||||||
|
Loading…
Reference in New Issue
Block a user