2022-04-08 19:24:43 +00:00
|
|
|
""" 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 """
|
2022-04-08 19:35:55 +00:00
|
|
|
ans = self.actions[task.action](task.deps, task.args)
|
2022-04-08 19:24:43 +00:00
|
|
|
return ans
|
|
|
|
|
|
|
|
def __next__(self):
|
2022-04-08 19:41:29 +00:00
|
|
|
task = self._tasks.pop(0)
|
2022-04-08 19:29:35 +00:00
|
|
|
ans = self.dispatch(task)
|
|
|
|
self._done.append(ans)
|
|
|
|
return ans
|