Michael Schwartz
12/03/2025, 11:55 AMawait elastic_sync(elastic_server=elastic_server, index_suffix=index_suffix)
await load_into_unifyd()
await data_entry_tables_synch(target_database="canna_prod")Marvin
12/03/2025, 11:55 AMMarvin
12/03/2025, 11:59 AMimport asyncio
# inside your async flow/function
results = await asyncio.gather(
elastic_sync(elastic_server=elastic_server, index_suffix=index_suffix),
load_into_unifyd(),
data_entry_tables_synch(target_database="canna_prod"),
)
r1, r2, r3 = results
A few useful variants:
- Let all run and collect errors without cancelling others:
results = await asyncio.gather(
elastic_sync(...),
load_into_unifyd(),
data_entry_tables_synch(...),
return_exceptions=True,
)
- Python 3.11+ structured concurrency:
import asyncio
async with asyncio.TaskGroup() as tg:
t1 = tg.create_task(elastic_sync(elastic_server=elastic_server, index_suffix=index_suffix))
t2 = tg.create_task(load_into_unifyd())
t3 = tg.create_task(data_entry_tables_synch(target_database="canna_prod"))
# On exit: waits for all; raises on first error by default
Notes:
- If these are Prefect async subflows (@flow and async def), they’re awaitable and will be tracked as subflows; gather is the simplest way to run them concurrently.
- If they’re sync or blocking, consider turning the inner work into Prefect tasks and using task.submit(...) to run them in parallel, then future.result().