How can I manage background tasks in FastAPI?

Viewed 405

I am creating a FastAPI application that is collecting user data in the background 24/7 and saving it to the DB. The API communicates with the data collector and I want it to be able to use multiple processes.

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 and discord bot to run in every process, but I also need to access the data throughout the API.

I learned that FastAPI has a BackgroundTask functionality, but that doesn't suit my need either.

Do I have to use some inter-proccess-communication? If so, what do you recommend?

0 Answers
Related