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

fix: support specify hooks after defining step #875

Merged
merged 1 commit into from
Oct 31, 2024
Merged
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
34 changes: 19 additions & 15 deletions src/dflow/step.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,21 +353,9 @@ def __init__(
self.id = self.name
self.template = template
self.hooks = {}
if success_hook is not None:
assert isinstance(success_hook, HookStep)
success_hook = deepcopy(success_hook)
success_hook.expression = "%s.status == 'Succeeded'" % self.expr
self.hooks["success"] = success_hook
if running_hook is not None:
assert isinstance(running_hook, HookStep)
running_hook = deepcopy(running_hook)
running_hook.expression = "%s.status == 'Running'" % self.expr
self.hooks["running"] = running_hook
if failure_hook is not None:
assert isinstance(failure_hook, HookStep)
failure_hook = deepcopy(failure_hook)
failure_hook.expression = "%s.status == 'Failed'" % self.expr
self.hooks["failure"] = failure_hook
self.success_hook = success_hook
self.running_hook = running_hook
self.failure_hook = failure_hook
self._with_param = with_param
self.with_param = with_param
if isinstance(self.with_param, str) and self.with_param.startswith(
Expand Down Expand Up @@ -1389,6 +1377,22 @@ def prepare_argo_arguments(self, context=None):
manifest=self.use_resource.get_manifest(self.template.command,
self.template.script))

if self.success_hook is not None:
assert isinstance(self.success_hook, HookStep)
success_hook = deepcopy(self.success_hook)
success_hook.expression = "%s.status == 'Succeeded'" % self.expr
self.hooks["success"] = success_hook
if self.running_hook is not None:
assert isinstance(self.running_hook, HookStep)
running_hook = deepcopy(self.running_hook)
running_hook.expression = "%s.status == 'Running'" % self.expr
self.hooks["running"] = running_hook
if self.failure_hook is not None:
assert isinstance(self.failure_hook, HookStep)
failure_hook = deepcopy(self.failure_hook)
failure_hook.expression = "%s.status == 'Failed'" % self.expr
self.hooks["failure"] = failure_hook

def convert_to_argo(self, context=None):
logging.debug("handle step %s" % self.name)
self.prepare_argo_arguments(context)
Expand Down
Loading