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

Running post tasks even if the main task fail #980

Open
mscansian opened this issue Dec 14, 2023 · 0 comments
Open

Running post tasks even if the main task fail #980

mscansian opened this issue Dec 14, 2023 · 0 comments

Comments

@mscansian
Copy link

Hello. I was wondering if there's a way to make sure that a post task runs even if the main task fails with an unhandled exception? Here's a simplified version of my code to illustrate the issue:

@task()
def my_pre_task(ctx):
    # Do some resource provisioning needed by the task


@task()
def my_post_task(ctx):
    # Perform resource cleanup
    # This should always run, but it won't if the main task fails with an unhandled exception


@task(pre=[my_pre_task], post=[my_post_task])
def main_task(ctx):
    # Do something that could also result in an unhandled exception

I know that I can wrap the main_task in a try/finally, but I'd rather not do this if I can find a more elegant solution. I was hoping there was something like post_run_on_failure=True that I could use, or a finally task that behaves like a post but always run.

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

No branches or pull requests

1 participant