2022-04-10 12:37:19 +00:00
|
|
|
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:
|
2022-04-13 13:09:08 +00:00
|
|
|
raise ActionNotFound(
|
|
|
|
f"The action {task.action} is not in {self._actions.keys()}"
|
|
|
|
)
|
2022-04-10 12:37:19 +00:00
|
|
|
|
2022-04-13 13:09:08 +00:00
|
|
|
return choosen_action(args=task.args, deps=task.deps, output=task.output)
|
2022-04-10 12:37:19 +00:00
|
|
|
|