<@ULVA73B9P> I'm trying to run prefect flows that ...
# ask-marvin
z
@Marvin I'm trying to run prefect flows that are able to be cancelled and paused. However, I'm having problems with run_deployment as the startup time for flows to be scheduled is too long. Is there any way to pause and cancel flows run without run_deployment?
m
Prefect provides functionalities to pause or cancel flow runs without needing to rely on
run_deployment
. Here are some options: 1. Pausing a Flow Run: Prefect allows you to pause an in-progress flow run for manual approval using the
pause_flow_run
function. More details can be found in the Prefect documentation. 2. Cancelling a Flow Run: You can directly cancel a flow run via Prefect. However, ensure the infrastructure block for the flow run supports cancellation. Any discrepancies might prevent successful cancellation. Here's a GitHub Issue discussing flow run SLAs including functionality for alerting, cancelling, or pausing deployments when flow runs exceed specified states like
Pending
or
Running
too long. Additional automation actions, like canceling or suspending flow runs, can be managed via the UI. This is detailed in the Prefect Automations documentation. To implement these operations, setting the appropriate environment variables is required:
Copy code
env
PREFECT_EXPERIMENTAL_EVENTS=True
PREFECT_API_SERVICES_TRIGGERS_ENABLED=True
Feel free to read more from this GitHub pull request for implementing automations. If you need any more specific code examples or further assistance, just let me know.
z
@Marvin I need to cancel or pause from outside of prefect. I've been doing it like this but it seems to take too long to take effect, if ever
Copy code
paused_state: State = State(type=StateType.PAUSED)
await client.set_flow_run_state(flow_run_id=run.id, state=paused_state)