To simulate a crashed flow in Prefect 3.0, you can intentionally raise an exception within your flow. Here's a simple example that raises a
SystemExit
exception to cause the flow to crash:
python
from prefect import flow
@flow
def boom_crash():
raise SystemExit("Boom crash")
if __name__ == "__main__":
boom_crash()
This flow,
boom_crash
, will enter a crashed state when run due to the
SystemExit
exception. You can use this to test your response to crashed flows.
For more information, you can refer to the
crashes.py example.
If you need to handle exceptions to convert them to a 'Crashed' state, you might find the
exception_to_crashed_state
function in the Prefect codebase useful. Unfortunately, the exact usage isn't detailed in the documentation, but you can explore the source code for more insights.