I'm trying to add background tasks to my middleware, but haven't found any official way to do it in their docs, this is what I have tried so far:
async def task1():
logging.info("Waiting ...")
time.sleep(5)
logging.info("Waited.")
@app.middleware("http")
async def add_process_time_header(request, call_next, bt=Depends(BackgroundTasks)):
a = bt.dependency()
a.add_task(task1)
a()
return await call_next(request)
This is blocking my requests, also shouldn't I be able to call async functions without await? I want to completely ignore the results of the background tasks, I dont need results from bg tasks