hi, is there a way to kill task in flow context? I know how to start a task in there, fairly easy. But not to kill a started one.
k
Kevin Kho
10/22/2021, 8:02 PM
You can
raise ENDRUN
. This will avoid any retries. Docs . Is this what you meant?
t
Tony Yun
10/22/2021, 8:05 PM
not really. For example, if I have a task A, inside of it, it’s calling another task B. But when I cancel the flow, the task A is cancelled. but task B is still running on background. I want a command to kill task B at task A’s finally statement.
Tony Yun
10/22/2021, 8:08 PM
or ask in another scenario, I have:
Copy code
with xxx as flow:
a = taskA()
# how to kill task a as a task?
is not a real task and in general, Prefect is currently not able to close hardware through cancelletation
t
Tony Yun
10/22/2021, 8:10 PM
yes that is right^
k
Kevin Kho
10/22/2021, 8:11 PM
Yeah in this case, there is no way I think. Cancelling
task_a
mid flow run through the flow is very hard. Because it must have already executed by the time downstream tasks are reached
t
Tony Yun
10/22/2021, 8:13 PM
if I can get some metadata from
RunNamespacedJob().run()
like task_id, I can call something like
client.set_task_run_state()
k
Kevin Kho
10/22/2021, 8:31 PM
Ah then in that case, you can’t get metadata from
RunNamespacedJob
from a downstream task unless you persist it in some location that can be retrieved from downstream.
If you are getting the metadata in the same task,you would need a modified task that allows you to poll the NamespacedJob or something or check the logs, and then you can have a conditional that
raise SUCCESS
or
raise FAIL
. These would be better than the
client.set_task_run_state()
if the logic is in the same task.
t
Tony Yun
10/23/2021, 12:26 AM
I see. Yeah I need to take a different approach. Thanks @Kevin Kho ! Have a good weekend.
Bring your towel and join one of the fastest growing data communities. Welcome to our second-generation open source orchestration platform, a completely rethought approach to dataflow automation.