Feat: append, dispatch and __next__ (basic) scheduler

This commit is contained in:
2022-04-08 21:24:43 +02:00
parent 6e718b987a
commit 7b64dcf8d6
2 changed files with 56 additions and 0 deletions

29
bopytex/scheduler.py Normal file
View File

@@ -0,0 +1,29 @@
""" Scheduler for action to make """
class Scheduler:
def __init__(self, actions: list):
self.actions = actions
self._tasks = []
self._done = []
@property
def tasks(self):
return self._tasks
@property
def done(self):
return self._done
def append(self, tasks):
self._tasks += tasks
def dispatch(self, task):
""" Do a task """
ans = self.actions[task.action](task.deps)
return ans
def __next__(self):
task = self._tasks.pop()
self._done.append(task.output)
return self.dispatch(task)