feat: dispatch transmit args to actions

This commit is contained in:
Bertrand Benjamin 2022-04-08 21:35:55 +02:00
parent 480ced3259
commit 4dbfe7a82c
2 changed files with 15 additions and 4 deletions

View File

@ -20,7 +20,7 @@ class Scheduler:
def dispatch(self, task):
""" Do a task """
ans = self.actions[task.action](task.deps)
ans = self.actions[task.action](task.deps, task.args)
return ans
def __next__(self):

View File

@ -3,14 +3,15 @@ from bopytex.scheduler import Scheduler
def test_schedule_append():
actions = {"DO": lambda _: "done"}
actions = {"DO": lambda deps, args: "done"}
scheduler = Scheduler(actions)
tasks = [Task(action="DO", args={}, deps=[])]
scheduler.append(tasks)
assert scheduler.tasks == tasks
def test_schedule_dispatch():
actions = {"DO": lambda _: "done"}
actions = {"DO": lambda deps, args: "done"}
scheduler = Scheduler(actions)
task = Task(action="DO", args={}, deps=[])
result = scheduler.dispatch(task)
@ -18,10 +19,20 @@ def test_schedule_dispatch():
def test_schedule_one_task():
actions = {"DO": lambda _: "done"}
actions = {"DO": lambda deps, args: "done"}
scheduler = Scheduler(actions)
scheduler.append([Task(action="DO", args={}, deps=[])])
result = scheduler.__next__()
assert result == "done"
assert scheduler.tasks == []
assert scheduler.done == ["done"]
def test_schedule_one_task_with_args():
actions = {"DO": lambda deps, args: f"{args['task']} done"}
scheduler = Scheduler(actions)
scheduler.append([Task(action="DO", args={"task": "one"}, deps=[])])
result = scheduler.__next__()
assert result == "one done"
assert scheduler.tasks == []
assert scheduler.done == ["one done"]