Feat: move action to worker with a dispatcher
This commit is contained in:
23
bopytex/worker/__init__.py
Normal file
23
bopytex/worker/__init__.py
Normal 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
28
bopytex/worker/worker.py
Normal 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,
|
||||
}
|
||||
Reference in New Issue
Block a user