Torstein Molland
01/05/2023, 9:34 AMfrom prefect import flow, get_run_logger, task
@task
async def async_task():
return "async_task"
@task
def synchronous_task():
return "synchronous_task"
@flow
async def my_flow():
logger = get_run_logger()
<http://logger.info|logger.info>("Executing async task:")
async_result = await async_task()
<http://logger.info|logger.info>(f"Result of async task was {async_result}")
<http://logger.info|logger.info>("Executing synchronous task")
synchronous_result = synchronous_task()
<http://logger.info|logger.info>(f"Result of synchronous task was {synchronous_result}")
Dmytro Ponomarchuk
01/05/2023, 9:50 AM.submit()
function to call the async task.
According to https://docs.prefect.io/tutorials/execution/#asynchronous-executionTorstein Molland
01/05/2023, 9:57 AMNate
01/05/2023, 4:42 PM.submit()
, you can await async tasks in your flow like a normal async function. The only time you really need submit()
is when you want to leverage a specific task runner's style of executionTorstein Molland
01/05/2023, 4:46 PM