I've developed a backend project using Python. It collects data from different sources, process the data, and then perform actions with it (for example, store relevant info in a database). To execute it, I just do python main.py
and it starts the daemon process.
Now I want to add a Flask API in order to interact with this collector: start/stop the collection, see the state of each component, add/remove components... What is the best approach to do it? I can't just add Flask app object and routes to the same project, because when I deploy the Api using Gunicorn with several workers, it runs several instances of the collector.
For example: I have in the collector a object called GlobalManager
that is in charge of creating, deleting, starting and stoping the collector's components. Obviously, there is only one instance of this GlobalManager
, so I can't include it in a project with Flask, because if I run it with Gunicorn, it starts several instances of the GlobalManager
.
Should I code the API in a separate project and the communicate both the API and the collector through some tool?