How can I control the final state of a flow run?

Prefect 2.0

The final state of the flow is determined by its return value. If a flow returns one or more task run futures or states, these runs are used as the reference tasks to determine the final state of the run. If any of the returned task runs fail, the flow run is marked as failed. You can read more in the following documentation page.

Prefect 1.0

Prefect 1.0 uses reference tasks to determine the final state of a flow run. Here is the syntax for setting reference tasks:

flow.set_reference_tasks([task_1, task_2])

Additionally, Prefect 1.0 has a concept of terminal state handlers that allow to set the final state of a flow run by using a Callable.