Hen rik
11/20/2023, 8:31 PMMarvin
11/20/2023, 8:31 PMFailed
and the flow will continue to execute the remaining tasks. The flow run will continue even if a task fails.
You can find more details in the Prefect documentation here.Hen rik
11/20/2023, 8:33 PMMarvin
11/20/2023, 8:34 PMskip_on_upstream_skip
parameter in your task decorator. This will allow the flow to continue even if a task fails.
Here is an example:
from prefect import task, Flow
@task(skip_on_upstream_skip=False)
def fail_task():
raise ValueError("I fail successfully")
@task
def success_task():
print("I'm fail safe!")
with Flow("My Flow") as flow:
fail_task()
success_task()
flow.run() # This will print "I'm fail safe!" even though fail_task() raises an exception
In this example, success_task
will run even if fail_task
fails because skip_on_upstream_skip=False
in the @task
decorator for fail_task
.
Please refer to the Prefect documentation for more details: Prefect DocsHen rik
11/20/2023, 8:35 PMMarvin
11/20/2023, 8:35 PMFailed
and the flow run will continue with the remaining tasks. However, you can change this behavior by using the skip_on_upstream_skip
parameter in your task decorator. This will allow the flow to continue even if a task fails.
Here is an example:
from prefect import task, Flow
@task(skip_on_upstream_skip=False)
def fail_task():
raise ValueError("I fail successfully")
@task
def success_task():
print("I'm fail safe!")
with Flow("My Flow") as flow:
fail_task()
success_task()
flow.run() # This will print "I'm fail safe!" even though fail_task() raises an exception
In this example, success_task
will run even if fail_task
fails because skip_on_upstream_skip=False
in the @task
decorator for fail_task
.
Please refer to the Prefect documentation for more details: Prefect DocsHen rik
11/20/2023, 8:36 PMMarvin
11/20/2023, 8:36 PMskip_on_failure
parameter to True
in your task decorator. This will allow the flow to continue even if a task fails.
Here is an example:
from prefect import task, Flow
@task(skip_on_failure=True)
def fail_task():
raise ValueError("I fail successfully")
@task
def success_task():
print("I'm fail safe!")
with Flow("My Flow") as flow:
fail_task()
success_task()
flow.run() # This will print "I'm fail safe!" even though fail_task() raises an exception
In this example, success_task
will run even if fail_task
fails because skip_on_failure=True
in the @task
decorator for fail_task
.
Please refer to the Prefect documentation for more details: Prefect DocsHen rik
11/20/2023, 8:41 PMMarvin
11/20/2023, 8:42 PMreturn_state=True
parameter when calling a task. This will return the state of the task instead of its result. If the task fails, you can check if the state is failed and handle the exception accordingly.
Here is an example:
from prefect import task, Flow
@task
def fail_task():
raise ValueError("I fail successfully")
@task
def success_task():
print("I'm fail safe!")
with Flow("My Flow") as flow:
state = fail_task(return_state=True)
if state.is_failed():
print("Oh no! The task failed. Falling back to '1'.")
result = 1
else:
result = state.result()
success_task()
flow.run() # This will print "Oh no! The task failed. Falling back to '1'." and "I'm fail safe!"
In this example, success_task
will run even if fail_task
fails because we handle the exception from fail_task
and continue with the flow.
Please refer to the Prefect documentation for more details: Prefect DocsNate
11/20/2023, 9:22 PMreturn_state=True
@Marvin please find a usage example of return_state=True