Ross Teach
08/09/2022, 8:26 PMAnna Geller
08/10/2022, 12:15 AMIs there any way to end a flow early conditionally without a failed state.yes, 100% you can e.g. return a state early - a silly flow example that shows how you can return states:
from prefect import task, flow
from prefect.orion.schemas.states import Completed, Failed
@task
def always_fails_task():
raise ValueError("I fail successfully")
@task
def always_succeeds_task():
print("I'm fail safe!")
return "success"
@flow
def return_state_manually():
x = always_fails_task.submit() # .result(raise_on_failure=False)
y = always_succeeds_task.submit()
if y.result() == "success":
return Completed(message="I am happy with this result")
else:
return Failed(message="How did this happen!?")
if __name__ == "__main__":
return_state_manually()