feat: run the scheduler

This commit is contained in:
2022-04-08 22:04:47 +02:00
parent e0377a3e92
commit 2b0c325203
2 changed files with 50 additions and 10 deletions

View File

@@ -1,6 +1,9 @@
""" Scheduler for action to make """
from logging import exception
class Scheduler:
def __init__(self, actions: list):
self.actions = actions
@@ -23,15 +26,32 @@ class Scheduler:
ans = self.actions[task.action](task.deps, task.args)
return ans
def __iter__(self):
return self
def __next__(self):
return self.next()
def next(self):
undoable = []
task = self._tasks.pop(0)
try:
task = self._tasks.pop(0)
except IndexError:
raise StopIteration
while not all([d in self.done for d in task.deps]):
undoable.append(task)
task = self._tasks.pop(0)
try:
task = self._tasks.pop(0)
except IndexError:
self.append(undoable)
raise StopIteration
self.append(undoable)
ans = self.dispatch(task)
self._done.append(ans)
return ans
def run(self):
for i in self:
pass