https://prefect.io logo
Title
g

George Coyne

10/30/2019, 5:35 PM
Hey everyone, what’s the best way to set a task to run last and always run, I am using the
all_finished
trigger but for whatever reason the task is running first. Thanks in advance
c

Chris White

10/30/2019, 5:37 PM
Hey George! I’d recommend the following to ensure it’s always the final task: 1.) create your flow without the final task 2.) after you’ve done this, add your final task to the flow as follows:
flow.set_dependencies(final_task, upstream_tasks=list(flow.terminal_tasks()))
and using an
all_finished
trigger is the correct trigger 👍
a

Argemiro Neto

10/30/2019, 5:42 PM
@George Coyne I'm using something like this:
final_task_var = this_is_the_final_task()
my_new_final_task_var = my_final_task()
my_new_final_task_var.set_upstream([final_task_var])
g

George Coyne

10/30/2019, 5:44 PM
Awesome thanks!
@Chris White Are there any more complex examples of imperative flows out there? I am having a hard time restructuring my flow here
c

Chris White

10/30/2019, 7:23 PM
There aren’t too many documented imperative examples unfortunately, but here’s another one in case you haven’t seen it: https://docs.prefect.io/core/examples/imperative_docker.html
is there a particular pattern / situation you’re currently struggling with?
j

Jeremiah

10/30/2019, 7:32 PM
Hey @George Coyne - just reading between the lines on your original question (so forgive me if I’m off base), all triggers refer to a task’s upstream tasks. So
all_finished
means “when all tasks upstream of this task are finished” rather than “when all tasks of the flow are finished”. If you make this task sit downstream of all the other tasks, as in Chris’s first example, then it will have the behavior you want where it truly runs after ALL other tasks have finished. Apologies if that was already clear to you but just wanted to be sure!