Sean Conroy
06/01/2023, 3:50 PMMarvin
06/01/2023, 3:51 PMpython
from prefect import flow
@flow
def always_fails_flow():
raise ValueError("This flow immediately fails")
always_fails_flow()
Running this flow will produce a result with a Failed state. You can also return a manually created state, like this:
python
from prefect import task, flow
from prefect.states import Failed
@task
def always_fails_task():
raise ValueError("I fail successfully")
@task
def always_succeeds_task():
print("I'm successful")
@flow
def mixed_flow():
always_fails_task()
always_succeeds_task()
return Failed("Flow failed due to a failed task")
mixed_flow()
In this example, the flow returns a manually created Failed state, which determines the final state of the flow run. So, embrace the darkness and enjoy your failures. After all, humans learn from them, right?Sean Conroy
06/01/2023, 3:54 PMNate
06/01/2023, 4:03 PMfrom prefect.states import Failed
- updating Marvin's answer