Feat: Integrate message in service, scheduler and dispatcher
This commit is contained in:
@@ -16,6 +16,9 @@ class Message():
|
||||
def err(self):
|
||||
return self._err
|
||||
|
||||
def __repr__(self):
|
||||
return f"Message(status={self.status}, out={self.out}, err={self.err})"
|
||||
|
||||
class SubprocessMessage(Message):
|
||||
def __init__(self, process):
|
||||
self._process = process
|
||||
|
@@ -2,12 +2,14 @@
|
||||
|
||||
|
||||
from bopytex.tasks import Task
|
||||
from bopytex.worker import Dispatcher
|
||||
|
||||
|
||||
class Scheduler:
|
||||
"""Scheduler is responsible of getting tasks (the tasks) and yield those that can be done"""
|
||||
|
||||
def __init__(self, done: list[str] = None):
|
||||
def __init__(self, dispatcher:Dispatcher, done: list[str] = None):
|
||||
self._dispatcher = dispatcher
|
||||
|
||||
if done is None:
|
||||
self._done = []
|
||||
@@ -56,9 +58,13 @@ class Scheduler:
|
||||
except IndexError:
|
||||
raise StopIteration
|
||||
|
||||
self._done.append(task.output)
|
||||
self._tasks.remove(task)
|
||||
return task
|
||||
message = self._dispatcher(task)
|
||||
|
||||
if message.status == 0:
|
||||
self._done.append(task.output)
|
||||
|
||||
return message
|
||||
|
||||
def backlog(self):
|
||||
""" Yield tasks sorted according to dependencies """
|
||||
|
@@ -15,11 +15,11 @@ def orcherstrator(
|
||||
):
|
||||
tasks = planner(options)
|
||||
|
||||
scheduler = Scheduler([options["template"]])
|
||||
scheduler = Scheduler(dispatcher, [options["template"]])
|
||||
scheduler.append(tasks)
|
||||
|
||||
for task in scheduler.backlog():
|
||||
yield from dispatcher(task)
|
||||
for message in scheduler.backlog():
|
||||
yield message
|
||||
|
||||
|
||||
# -----------------------------
|
||||
|
@@ -10,14 +10,9 @@ class Dispatcher:
|
||||
try:
|
||||
choosen_action = self._actions[task.action]
|
||||
except KeyError:
|
||||
raise ActionNotFound(f"The action {task.action} is not in {self._actions.keys()}")
|
||||
raise ActionNotFound(
|
||||
f"The action {task.action} is not in {self._actions.keys()}"
|
||||
)
|
||||
|
||||
return choosen_action(
|
||||
args=task.args,
|
||||
deps=task.deps,
|
||||
output=task.output
|
||||
)
|
||||
|
||||
def fake_worker(args, deps, output):
|
||||
yield f"FAKE - {args} - {deps} - {output}"
|
||||
return choosen_action(args=task.args, deps=task.deps, output=task.output)
|
||||
|
||||
|
Reference in New Issue
Block a user