feat: schelule multiple task
This commit is contained in:
parent
4dbfe7a82c
commit
bfe9e6f91e
@ -24,7 +24,7 @@ class Scheduler:
|
||||
return ans
|
||||
|
||||
def __next__(self):
|
||||
task = self._tasks.pop()
|
||||
task = self._tasks.pop(0)
|
||||
ans = self.dispatch(task)
|
||||
self._done.append(ans)
|
||||
return ans
|
||||
|
@ -36,3 +36,26 @@ def test_schedule_one_task_with_args():
|
||||
assert result == "one done"
|
||||
assert scheduler.tasks == []
|
||||
assert scheduler.done == ["one done"]
|
||||
|
||||
|
||||
def test_schedule_multiple_tasks():
|
||||
actions = {"DO": lambda deps, args: f"{args['task']} done"}
|
||||
scheduler = Scheduler(actions)
|
||||
t1 = Task(action="DO", args={"task": "one"}, deps=[])
|
||||
t2 = Task(action="DO", args={"task": "two"}, deps=[])
|
||||
t3 = Task(action="DO", args={"task": "three"}, deps=[])
|
||||
scheduler.append([t1, t2, t3])
|
||||
result = scheduler.__next__()
|
||||
assert result == "one done"
|
||||
assert scheduler.tasks == [t2, t3]
|
||||
assert scheduler.done == ["one done"]
|
||||
|
||||
result = scheduler.__next__()
|
||||
assert result == "two done"
|
||||
assert scheduler.tasks == [t3]
|
||||
assert scheduler.done == ["one done", "two done"]
|
||||
|
||||
result = scheduler.__next__()
|
||||
assert result == "three done"
|
||||
assert scheduler.tasks == []
|
||||
assert scheduler.done == ["one done", "two done", "three done"]
|
||||
|
Loading…
Reference in New Issue
Block a user