Feat: scheduler don't manage actions
This commit is contained in:
@@ -5,8 +5,9 @@ from bopytex.tasks import Task
|
||||
|
||||
|
||||
class Scheduler:
|
||||
def __init__(self, actions: dict, done: list[str] = None):
|
||||
self.actions = actions
|
||||
"""Scheduler is responsible of getting tasks (the tasks) and yield those that can be done"""
|
||||
|
||||
def __init__(self, done: list[str] = None):
|
||||
|
||||
if done is None:
|
||||
self._done = []
|
||||
@@ -17,12 +18,12 @@ class Scheduler:
|
||||
|
||||
@property
|
||||
def tasks(self) -> list[Task]:
|
||||
""" list all the tasks """
|
||||
"""List all the tasks todo"""
|
||||
return self._tasks
|
||||
|
||||
@property
|
||||
def doable_tasks(self) -> list[Task]:
|
||||
""" list all doable tasks """
|
||||
"""List all doable tasks"""
|
||||
return [
|
||||
task
|
||||
for task in self.tasks
|
||||
@@ -31,12 +32,12 @@ class Scheduler:
|
||||
|
||||
@property
|
||||
def all_deps(self) -> list[str]:
|
||||
""" List dependencies of all tasks """
|
||||
"""List dependencies of all tasks"""
|
||||
return {d for task in self.tasks for d in task.deps}
|
||||
|
||||
@property
|
||||
def all_output(self) -> list[str]:
|
||||
""" List ouput of all tasks """
|
||||
"""List ouput of all tasks"""
|
||||
return {task.output for task in self.tasks}
|
||||
|
||||
@property
|
||||
@@ -46,31 +47,20 @@ class Scheduler:
|
||||
def append(self, tasks: list[Task]):
|
||||
self._tasks += tasks
|
||||
|
||||
def dispatch(self, task):
|
||||
"""Do a task"""
|
||||
ans = self.actions[task.action](task.deps, task.args, task.output)
|
||||
return ans
|
||||
def is_finishable(self):
|
||||
return self.all_deps.issubset(self.all_output)
|
||||
|
||||
def __iter__(self):
|
||||
return self
|
||||
|
||||
def __next__(self):
|
||||
return self.next()
|
||||
|
||||
def next(self):
|
||||
def next_task(self):
|
||||
try:
|
||||
task = self.doable_tasks[0]
|
||||
except IndexError:
|
||||
raise StopIteration
|
||||
|
||||
ans = self.dispatch(task)
|
||||
self._done.append(task.output)
|
||||
self._tasks.remove(task)
|
||||
return ans
|
||||
return task
|
||||
|
||||
def run(self):
|
||||
for _ in self:
|
||||
pass
|
||||
|
||||
def is_finishable(self):
|
||||
return self.all_deps.issubset(self.all_output)
|
||||
def backlog(self):
|
||||
""" Yield tasks sorted according to dependencies """
|
||||
while self.doable_tasks:
|
||||
yield self.next_task()
|
||||
|
Reference in New Issue
Block a user