Nikita Vostretsov
02/17/2020, 6:48 AMt1
-t3
) or lower branch (t1
, t4
and t5
). Is it possible to do without rewriting code from
with Flow('flow') as flow:
r1 = t1()
r2 = t2(r1)
r3 = t3(r2)
r4 = t1(r1)
r5 = t5(r4)
into
def upper_branch():
r1 = t1()
r2 = t2(r1)
r3 = t3(r2)
def lower_branch():
r1 = t1()
r4 = t4(r1)
r5 = t5(r2)
with Flow('flow') as flow:
if do_upper or do_both:
upper_branch()
if do_lower or do_both:
lower_branch()
trapped
02/17/2020, 2:57 PMJeremiah
02/17/2020, 3:56 PMNikita Vostretsov
02/18/2020, 7:28 AMif
. I was thinking about something like
with Flow('flow') as flow:
r1 = t1()
r2 = t2(r1)
r3 = t3(r2)
r4 = t1(r1)
r5 = t5(r4)
targets = []
if do_upper or do_both:
targets.append(r3)
if do_upper or do_both:
targets.append(r5)
flow.run(targets=targets)
Jeremiah
02/18/2020, 4:29 PMif
is not available inside a flow since it is executed at “build time”; Prefect’s ifelse
is executed at “run time” and can therefore depend on information available when the flow runs. In your example, the flow actually runs both branches no matter what, as you have no runtime control flow implemented. The only thing changing is the input to your targets
keyword argument, which is presumably a Parameter not shown here.ifelse
is intended for; you want to make a decision at runtime about which branch to execute. If, on the other hand, you know which branch you want to run AND you don’t mind rebuilding your flow each time (which might be fine for your purposes!), then you could use a Python if
to control which tasks you add to the flow. However, if you want a single flow with multiple branches, you’ll need a Prefect ifelse
.