Reputation: 967
I have a pyramid + sqlalchemy based web server. I need to start a Unix sub-process when user enters a particular request. Afterwards, I would like the server to monitor this sub-process regularly and update the tables based on the partial result. When the sub-process is finished, a set of actions are to be performed by the server. What is the best way to achieve this?
I am thinking of starting a thread which will initiate a request at regular intervals. As part of serving this request, the server will monitor the open processes and update the tables. Is there any better way to do this?
Upvotes: 1
Views: 208
Reputation: 18060
The most common way to achieve this kind of thing is to use a message queue and a worker. For example, you could use Celery or RQ.
The first requests that would start your job will instead send a message so that the job is done by the worker. The worker can then do whatever it needs to do. If you need to update the UI of your web app, you can poll (make a request each seconds to see the latest state). If you need something real-time, you can have a look at how you can send a message back to your user with websockets or server-sent events.
Upvotes: 3