Django, Signals and another process

I have a good Django project and a separate background process that will collect data from different sources and store this data in an index.

I have a model in a Django application called Sources that contains, in fact, a list of sources from which data can come! I managed to create a signal that is activated / called when a new record is placed in the Sources model.

My question is, is there an easy way for anyone to know for what reasons I can send some form of signal / message to the background process, indicating that the Sources model has been changed? Or should I just resort to polling the changes every x seconds because it is so much easier?

Thanks so much for the help received.

+4
source share
2 answers

It is unclear how you are using the background process you are talking about.

In any case, I would suggest that you use the Sources model directly in the background task. There are convenient ways to start a task without leaving the Django area (to have access to your models. For example, you can use Celery [1] or RQ [2].

Then you do not need to send any messages, any changes to the Sources model will take effect the next time you run your task.

[1] Celery is an open source asynchronous task / task queue queue, it is easy to configure and integrate well with Django.

[2] RQ stands for "Redis Queue", it is a "simple Python library for queuing and processing them in the background by workers.

+5
source

Polling is probably the easiest if you don't need split second latency.

If you do, then you probably want to study, say,

  • sending a UNIX signal (or other IPC methods, depending on the platform) for the process
  • having a background process, has a simple listening socket that you just send, say, a byte (which, admittedly, is an IPC form), and triggers the action you want to call
  • or any task / message queue. Celery or ZeroMQ come to mind.
+1
source

All Articles