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

Exithandler with email/slack push #11172

Open
ianbenlolo opened this issue Sep 5, 2024 Discussed in #10955 · 1 comment
Open

Exithandler with email/slack push #11172

ianbenlolo opened this issue Sep 5, 2024 Discussed in #10955 · 1 comment
Labels
lifecycle/stale The issue / pull request is stale, any activities remove this label.

Comments

@ianbenlolo
Copy link

Discussed in #10955

Originally posted by ianbenlolo June 25, 2024
Hey,

This may be a duplicate but I have not found this exact question so apologies in advance.

I have a pipeline that i would like to add an exithandler that runs some cleanup code and sends an email.
This is how I've done it so far:

@dsl.component
def dummy_print_action(action: str):
    print(action)

@dsl.pipeline
def send_failure_email(
    email_recipients
):
    # this was a hack required to use the VertexNotificationEmailOp component only when the pipeline fails
    exit_handler_task = vertex_notification_email.VertexNotificationEmailOp(recipients=email_recipients)

    with dsl.ExitHandler(exit_task=exit_handler_task, name="Dummy exit handler"):
        _ = dummy_print_action(
                action=f"Failed pipeline, sending notification email to {email_recipients}"
            )
@dsl.pipeline
def exit_handler(
    email_recipients: List[str],
    status: dsl.PipelineTaskFinalStatus,
):
    get_run_state_task = get_run_state(status=status)

    with dsl.Condition(
        get_run_state_task.output != "SUCCEEDED", name="state != SUCCEEDED"
    ):
        _ = cleanup()
        _ = send_failure_email(
            email_recipients=email_recipients,
        )

@dsl.pipeline
def pipeline(args):
    exit_handler_task = exit_handler(email_recipients=["[email protected]"],)
    with dsl.ExitHandler(exit_task=exit_handler_task, name="Pipeline"):
        pipeline_stuff()

But this is a little cumbersome. I was wondering if there is an easier way to do this?

Furthermore, i'd like to send a slack notification on failure and haven't found a way to other than the link but I'm unsure how to set up the necessary image.

Thank you!

Copy link

github-actions bot commented Nov 5, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the lifecycle/stale The issue / pull request is stale, any activities remove this label. label Nov 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lifecycle/stale The issue / pull request is stale, any activities remove this label.
Projects
None yet
Development

No branches or pull requests

1 participant