r/FastAPI • u/jackstar_12 • Apr 03 '22
Question Manage background activity
Hey guys.
I am creating an FastAPI application that is collecting user data in the background 24/7 and saving it to the DB.
I was wondering:
How would I go about implementing something like this in a multi-worker environemnt? Because I don't want the data collection task to run in every process, but I also need to access the data throughout the API.
3
Upvotes
1
u/jackstar_12 Apr 04 '22
In this case I thought about the collector as a seperate process that communicates with the uvicorn instances created by gunicorn. It's not really scheduled as it runs 24/7, holding multiple websockets.
The FastAPI instances don't control the collector. They only tell him when e.g. a new user is added, so the collector can include that one too.