Bopytex/bopytex/scheduler.py

38 lines
823 B
Python

""" 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, task.args)
return ans
def __next__(self):
undoable = []
task = self._tasks.pop(0)
while not all([d in self.done for d in task.deps]):
undoable.append(task)
task = self._tasks.pop(0)
self.append(undoable)
ans = self.dispatch(task)
self._done.append(ans)
return ans