https://prefect.io logo
Title
i

itay livni

10/26/2019, 5:53 AM
Hi - I am trying to check if a task has successfully run in a flow and then based on that on a successful; or failed
task
completed do something. Something like
TaskRunner
state.is_successful()
but in a
flow
.
j

Jeremiah

10/26/2019, 2:54 PM
Hi Itay, are you saying you want to take a different action based on whether the upstream task succeeded or failed? I think we would suggest you create two downstream tasks, one with an
all_success
trigger and one with a
all_failed
trigger
i

itay livni

10/26/2019, 5:32 PM
Yes. But specifically how do you retrieve the
task
state
inside a
flow
? Is there something like
some_task,state.is_success
?
c

Chris White

10/26/2019, 5:37 PM
Hi itay - could you explain why you need this pattern?
Without knowing the context, typically I’d say if an upstream task needs to communicate information to a downstream task it should do so by returning data which the downstream task receives, otherwise you run the risk of introducing a dependency that Prefect can’t track
i

itay livni

10/26/2019, 5:46 PM
I run some task with`subprocesses` if task is success do something. If false do something else
c

Chris White

10/26/2019, 5:47 PM
gotcha, yea that sounds like a perfect use case for either a trigger or an
ifelse
branch
i

itay livni

10/26/2019, 5:52 PM
yeah so i was planning to use ifelse. So specifically what is the syntax to capture the task state. The documentation had examples for post-flow analysis
c

Chris White

10/26/2019, 7:31 PM
task states are the currency of Prefect itself, and in general are only exposed to users in the following scenarios: - triggers - state handlers - post-flow analysis, as you mention It seems from your description that you don’t need to capture this state yourself; for example, you could subclass the Prefect ShellTask and instead of failing when the command fails, simply return
False
--> then the
ifelse
operator will branch based on command success / failure
i

itay livni

10/26/2019, 8:37 PM
ok thamks