Is it possible to force a flow to finish in a skip...
# ask-community
a
Is it possible to force a flow to finish in a skipped state? I've tried using the terminal_state_handler:
def terminal_state_handler(flow, state, reference_task_states):
for task_state in reference_task_states:
if task_state.is_skipped():
return Skipped(state.message, state.result, state.context, state.cached_inputs)
return state
which kind of works, however the UI is still counting the duration as if it was still running...
k
Hey @Andre Muraro, what is the use case of making it Skipped at the end of the Flow? I think at that point the flow has already suceeded so what are you skipping?
a
@Kevin Kho basically I have an api which I have to periodically ping to check whether it has new data for me. If it doesn't, I skip all processing. However the business side demands that I hit that api very frequently, which makes it a little hard to figure out which flow runs actually found data and which didn't, at a glance. So my idea was to cause flows to show as skipped, so as to easily distinguish them from the ones that actually found data to process.
k
Ahh I see. What you have there looks right to me. Let me see if this there is a better way to do it.
Chatted with the team and there’s a bunch of reasons why the duration keeps going up (there is no end date when SKIPPED). I think the only thing we can recommend here is to use ENDRUN instead to end the flow run. You can also raise SUCCESS with a message and maybe filter by the message?
a
Think I'm not familiar with this ENDRUN method. Got any docs on it?
k
It’s a signal so you would just
raise ENDRUN
similar to
raise FAIL
.
a
alright, I'll have a look at those options, thanks
j
I think Case would work: https://docs.prefect.io/api/latest/tasks/control_flow.html#case Will skip all tasks unless the condition is met.