Giacomo Chiarella
06/12/2023, 2:24 PMDeceivious
06/12/2023, 2:25 PMDeceivious
06/12/2023, 2:25 PMclient.set_flow_run_state
m looking into thisDeceivious
06/12/2023, 2:27 PMfrom prefect.client.schemas.filters import FlowRunFilterState
from prefect.states import Cancelling
running_flows=await client.read_flow_runs(
flow_run_filter=FlowRunFilter(state=FlowRunFilterState(name={"any_":["Running"]}))
)
for running_flow in running_flows:
print(running_flow.id,running_flow.name)
res=await client.set_flow_run_state(running_flow.id,Cancelling())
print(res)
Deceivious
06/12/2023, 2:27 PMGiacomo Chiarella
06/12/2023, 2:27 PMDeceivious
06/12/2023, 2:28 PMGiacomo Chiarella
06/12/2023, 2:28 PMDeceivious
06/12/2023, 2:28 PMDeceivious
06/12/2023, 2:28 PMGiacomo Chiarella
06/12/2023, 2:29 PMDeceivious
06/12/2023, 2:29 PMDeceivious
06/12/2023, 2:29 PMDeceivious
06/12/2023, 2:29 PMGiacomo Chiarella
06/12/2023, 2:30 PMGiacomo Chiarella
06/12/2023, 2:30 PMGiacomo Chiarella
06/12/2023, 2:31 PMDeceivious
06/12/2023, 2:31 PMDeceivious
06/12/2023, 2:31 PMGiacomo Chiarella
06/12/2023, 2:31 PMDeceivious
06/12/2023, 2:32 PMGiacomo Chiarella
06/12/2023, 2:32 PMDeceivious
06/12/2023, 2:32 PMDeceivious
06/12/2023, 2:32 PMDeceivious
06/12/2023, 2:33 PMDeceivious
06/12/2023, 2:34 PMGiacomo Chiarella
06/12/2023, 2:34 PMDeceivious
06/12/2023, 2:34 PMDeceivious
06/12/2023, 2:34 PMGiacomo Chiarella
06/12/2023, 2:35 PMGiacomo Chiarella
06/12/2023, 2:43 PMGiacomo Chiarella
06/12/2023, 2:53 PMGiacomo Chiarella
06/12/2023, 2:53 PMDeceivious
06/12/2023, 2:57 PMDeceivious
06/12/2023, 2:57 PMGiacomo Chiarella
06/12/2023, 2:57 PMGiacomo Chiarella
06/12/2023, 3:00 PMread_deployment_by_name
Deceivious
06/12/2023, 3:18 PMclient.read_flow_runs
has deployment_idGiacomo Chiarella
06/12/2023, 3:20 PMGiacomo Chiarella
06/12/2023, 3:20 PMFlowRunContext.get().flow_run.deployment_id
does the trickJake Kaplan
06/12/2023, 3:20 PMCANCELLED
is a flow run state, the same way RUNNING
and COMPLETED
are states. The client uses /set_state
to a propose a cancelled state, just like any other state. This is the graceful way to stop a flow run in progress, especially if your flow run is executing on remote infrastructure.
Deleting a flow run that is in progress is equivalent to yanking the cord out the machine in the middle. It would stop but not gracefullyDeceivious
06/12/2023, 3:21 PMGiacomo Chiarella
06/12/2023, 3:22 PMJake Kaplan
06/12/2023, 3:33 PMCANCELLING
is the right state to pass, which indicates that the flow run should be prepared to be CANCELLED
Jake Kaplan
06/12/2023, 3:34 PMForce=True
, the code snippet above looks right at glance to cancel running flow runsGiacomo Chiarella
06/12/2023, 3:35 PMGiacomo Chiarella
06/12/2023, 3:35 PMDeceivious
06/12/2023, 3:35 PMJake Kaplan
06/12/2023, 3:38 PMJake Kaplan
06/12/2023, 3:39 PMforce=True
changes a state but tells the API to disregard most orchestration rules. I generally would not use it, it'll break expectations of what is "supposed to happen"Deceivious
06/12/2023, 3:39 PM