Skip to content

feature: support custom argo exit hooks #2446

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

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

saikonen
Copy link
Collaborator

@saikonen saikonen commented Jun 9, 2025

implementing support for running custom functions as exit hooks with argo workflows.

also refactors current lifecycle hook setup to use the same primitives.

Suggested UX for defining custom exit hooks in the flow file:

from time import sleep
from metaflow import step, FlowSpec, Parameter, run_on_finish

def success_print():
    print("Testing some custom exit function.")

def failure_print():
    print("Flow failed.")

@run_on_finish(functions=[success_print], on_success=True)
@run_on_finish(functions=[failure_print], on_error=True)
class NotifyFlow(FlowSpec):
    should_fail = Parameter(name='should_fail', default=False)

    @step
    def start(self):
        print("Starting 👋")
        print("Should fail?", self.should_fail)
        if self.should_fail:
            sleep(60)
            raise Exception("failing as expected")
        self.next(self.end)

    @step
    def end(self):
        print("Done! 🏁")


if __name__ == "__main__":
    NotifyFlow()

@saikonen saikonen requested a review from savingoyal June 9, 2025 12:51


class RunOnFinishDecorator(FlowDecorator):
name = "run_on_finish"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@exit_hook

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants