-
Hi, let's imagine I've got three tasks/functions running in parallel. They don't have any return statements. They download files from urls. Their runtime is different and sometimes different task finishes last. I want to start a fourth task ONLY after all three parallel tasks mentioned above finished execution. Is there a way to do it? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Not sure if it helps in your situation (Not tested in multiprocessing or async) but there is a The way it works is it will only execute a task after all the tasks passed into the function have run atleast once.
OUTPUT:
As you can see, task 4 runs after all three tasks have one time each. Because tasks 1 and 2 run more frequently than task 3, The output shows them running a couple times before task 3 runs again. Once task 3 runs, becuase all the tasks have run and complete this triggers task 4. In your case, if task 1, 2 and 3 run at the same frequency, it should only trigger task 4 once they have all finished. This is probably the best solution for your use case, but if it doesn't work in your scenario for whatever reason, you could also use some kind of global variable bodge with Rocketry params to track task states and then have "task 4" run more frequently and only execute once the tasks have finished running. Something like this
Not a big fan of that solution though, but it should work I think. Essentially each task is setting its own 'state' to True. Task 4 checks that all states are True and if not doesn't do anything. Once all are True task 4 can run, and once finished will set the task states back to 'False' again. |
Beta Was this translation helpful? Give feedback.
-
Thanks a lot @Jypear. A very helpful answer. I've never used rocketry and before investing my time in it I needed to know if I should dig deeper or go with things like Dagster, Prefect...etc. I see now that it makes sense to invest some time into reading the docs. My main objective will be to see how to make the three first functions run in parallel. I think while glancing over the docs, I saw a note that Rocketry has this functionality. Thanks again |
Beta Was this translation helpful? Give feedback.
Not sure if it helps in your situation (Not tested in multiprocessing or async) but there is a
after_all_finish
fromrocketry.conds
you can use. It accepts*args
from the tasks you want to run the task after.The way it works is it will only execute a task after all the tasks passed into the function have run atleast once.