Hey everyone, what’s the best way to set a task to...
# prefect-community
g
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
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:
Copy code
flow.set_dependencies(final_task, upstream_tasks=list(flow.terminal_tasks()))
and using an
all_finished
trigger is the correct trigger 👍
a
@George Coyne I'm using something like this:
Copy code
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
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
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
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!