Lucas Hosoya
01/04/2022, 12:49 PMstate.Cancelling
and state.Cancelled
as True
, but none of them occurs.
It only register as Cancelling
or Cancelled
when I put the flow to the State (UI) as Cancelled.
Another weird fact is if I put the State as Cancelled, my tasks keeps running until it finishes (either in fail or succeed).
I'm currently working on State handlers, how can I be sure that I'm cancelling my flow runs and consequently my tasks for that flow run?Lucas Hosoya
01/04/2022, 12:55 PMCancelled
, but the task is showing as Running
(but I know that the task is paused/stopped, because there are no outputs).Anna Geller
Lucas Hosoya
01/04/2022, 1:30 PMCancelled
or Failed
flow runs and send a POST do databricks in order to cancel the submitJob/submitRun since a databricks task only calls the POST run job and doesn't call the Cancel/Stop
whenever the flow stops.Anna Geller
Anna Geller
Lucas Hosoya
01/05/2022, 12:30 PMstate_handler
to the Flow and then sending a parameter with a condition for cancelled runs. I'm using a LocalDaskExecutor
which should be fine to send the https://<databricks-instance>/api/2.1/jobs/runs/cancel
.Anna Geller
if isinstance(new_state, prefect.engine.state.Cancelled)
Lucas Hosoya
01/06/2022, 8:42 PMdef canceled_state_handler(task, old_state, new_state):
if ((isinstance(new_state,state.Cancelling)) or (isinstance(new_state,state.Cancelled))):
cancel_run()
return new_state
def cancel_run():
cancel_url = f"{DOMAIN}api/2.0/jobs/runs/cancel"
cancel_payload = json.dumps({
"run_id": RUN_ID
})
requests.request("POST",url=cancel_url,headers=headers,data=cancel_payload)
This is what i've managed to do... still testing but it turned out pretty good. (used some global vars, trying to find out a way to not use with state handlers)Anna Geller