Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Done method before execute overridable closes #29 #30

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions prism/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ def set_task_manager(self, task_manager: prism.infra.task_manager.PrismTaskManag
def set_hooks(self, hooks: prism.infra.hooks.PrismHooks):
self.hooks = hooks

def _done(self, hooks: prism.infra.hooks.PrismHooks) -> bool:
"""
A protected method meant to be overrided by sub classes. Will be called
automatically at the begin of exec()
"""
return True


def exec(self):

# If the `target` decorator isn't applied, then only execute the `run` function
Expand All @@ -63,6 +71,10 @@ def exec(self):
# If bool_run, then execute the `run` function and set the `output`
# attribute to its result
if self.bool_run:
if not self._done(self.hooks):
raise prism.exceptions.RuntimeException(
f"the _done method in {type(self).__name__} failed to execute")

self.output = self.run(self.task_manager, self.hooks)
if self.output is None:
raise prism.exceptions.RuntimeException(
Expand Down
Loading