Feat: move action to worker with a dispatcher

This commit is contained in:
2022-04-10 14:37:19 +02:00
parent 3f1464f3f6
commit 08411bd42d
5 changed files with 36 additions and 9 deletions

View File

@@ -0,0 +1,23 @@
class ActionNotFound(Exception):
pass
class Dispatcher:
def __init__(self, actions: list):
self._actions = actions
def __call__(self, task):
try:
choosen_action = self._actions[task.action]
except KeyError:
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}"

28
bopytex/worker/worker.py Normal file
View File

@@ -0,0 +1,28 @@
""" A worker consumes tasks """
def generate():
pass
def compile():
pass
def activate_corr():
pass
def join_pdf():
pass
def clean():
pass
WORKERS = {
"GENERATE": generate,
"COMPILE": compile,
"ACTIVATE_CORR": activate_corr,
"JOIN_PDF": join_pdf,
"CLEAN": clean,
}