Creating asynchronous background tasks
In Chapter 2, Exploring the Core Features, we first showcased the BackgroundTasks injectable API class, but we didn’t mention creating asynchronous background tasks. In this discussion, we will be focusing on creating asynchronous background tasks using the asyncio module and coroutines.
Using the coroutines
The framework supports the creation and execution of asynchronous background processes using the async/await structure. The following native service is an asynchronous transaction that generates a billing sheet in CSV format in the background:
async def generate_billing_sheet(billing_date, query_list): Â Â Â Â filepath = os.getcwd() + '/data/billing-' + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â str(billing_date) +'.csv' Â Â Â Â with open(filepath, mode="a") as sheet: Â Â Â Â Â ...