diff --git a/bopytex/scheduler.py b/bopytex/scheduler.py index 34b68b7..0e22d98 100644 --- a/bopytex/scheduler.py +++ b/bopytex/scheduler.py @@ -16,11 +16,13 @@ class Scheduler: self._tasks = [] @property - def tasks(self): + def tasks(self) -> list[Task]: + """ list all the tasks """ return self._tasks @property - def doable_tasks(self): + def doable_tasks(self) -> list[Task]: + """ list all doable tasks """ return [ task for task in self.tasks @@ -28,15 +30,17 @@ class Scheduler: ] @property - def all_deps(self): + def all_deps(self) -> list[str]: + """ List dependencies of all tasks """ return {d for task in self.tasks for d in task.deps} @property - def all_output(self): + def all_output(self) -> list[str]: + """ List ouput of all tasks """ return {task.output for task in self.tasks} @property - def done(self): + def done(self) -> list[str]: return self._done def append(self, tasks: list[Task]): @@ -54,24 +58,14 @@ class Scheduler: return self.next() def next(self): - undoable = [] - try: - task = self._tasks.pop(0) + task = self.doable_tasks[0] except IndexError: raise StopIteration - while not all([d in self.done for d in task.deps]): - undoable.append(task) - try: - task = self._tasks.pop(0) - except IndexError: - self.append(undoable) - raise StopIteration - - self.append(undoable) ans = self.dispatch(task) self._done.append(task.output) + self._tasks.remove(task) return ans def run(self):