Dev Dabke
12/27/2024, 9:06 PMb
depends on all of the a
tasks, but c
could be running completely independently.
async def main():
"""Do something."""
a_1 = task_a_n(n=1)
a_2 = task_a_n(n=2)
a_3 = task_a_n(n=3)
a = await asyncio.gather(a_1, a_2, a_3)
b = await task_b(needs=a) # note that this does not actually take a as input, but I'm just writing it here for clarity on dependencies
c = await task_c()
# Finally, message passing
await task_d(needs=(b, c))
Using Prefect magic that seems to be going away, we could write:
async def main():
"""Do something."""
a_1 = task_a_n(n=1)
a_2 = task_a_n(n=2)
a_3 = task_a_n(n=3)
b = task_b(wait_for=[a_1, a_2, a_3])
c = task_c()
# Finally, message passing
await task_d(wait_for=[b, c])
What's the canonical or pythonic way to correctly represent these complex/transitive dependencies without doing something ugly?Janet Carson
12/27/2024, 11:52 PMa_1, a_2, a_3 = task_a_n.map([1,2,3])
perhaps?
https://docs.prefect.io/v3/develop/task-runners#mapping-over-iterablesDev Dabke
12/27/2024, 11:54 PMasync def main():
"""Do something."""
a_1 = task_a_n.submit(n=1)
a_2 = task_a_n.submit(n=2)
a_3 = task_a_n.submit(n=3)
b = task_b.submit(wait_for=[a_1, a_2, a_3])
c = task_c.submit()
# Finally, message passing
await task_d.submit(wait_for=[b, c])
Dev Dabke
12/27/2024, 11:54 PM.submit
system to dispatch tasks, including async
ones. Maybe that's totally allowed?Janet Carson
12/28/2024, 12:02 AMtask_a_n
to task_b
so that prefect is in charge of managing the dependency order. You don't wait to await task_d.submit
on the last line, you want to use prefect's awaiter from prefect.futures import wait
or resolve_futures_to_states
as submit returns a PrefectFuture https://prefect-python-sdk-docs.netlify.app/prefect/futures/Dev Dabke
12/28/2024, 12:10 AMwait
call.Janet Carson
12/28/2024, 12:15 AMDev Dabke
12/28/2024, 12:24 AMraise_on_failure=False
, will background tasks correctly cause the flow to fail?Dev Dabke
12/28/2024, 12:24 AMDev Dabke
12/28/2024, 12:25 AMDev Dabke
12/28/2024, 12:25 AMJanet Carson
12/28/2024, 12:27 AMDev Dabke
12/28/2024, 12:28 AMDev Dabke
12/28/2024, 12:28 AMDev Dabke
12/28/2024, 12:28 AMasync
tasks to make sure the upgrade doesn't break everything 🙂Janet Carson
12/28/2024, 12:29 AM