0

I have a custom django management command that is constantly running through the supervisor (keep alive)

I need under certain circumstances (for example, a signal in the project, or a change in the database) the django management process reacted to these changes.

Tried looking for something similar but can't seem to find a simple implementation.

UPD: In the management command I start the stream process to the twitter API to track new tweets for the tags from django database. When adding a new tag to the database, I want to restart the stream connection.

  • What's the data and what will your command do with the data? What does your management command do? Can you add your management command to the question? – Iain Shelvington Nov 29 '21 at 20:09
  • Any kind of [IPC](https://docs.python.org/3/library/ipc.html) will do. – Klaus D. Nov 29 '21 at 20:12
  • In the management command I start the stream process to the twitter API to track new tweets for the tags from django database. When adding a new tag to the database, I want to restart the stream connection. – Dmitry Reva Nov 29 '21 at 20:17
  • Something like [channels](https://channels.readthedocs.io/en/stable/) would potentially work here. A quick and dirty solution would be to just poll the DB and react when there is a change – Iain Shelvington Nov 29 '21 at 20:26
  • This is exactly the problem. How does Django management command receive signal from django-channels? – Dmitry Reva Nov 29 '21 at 20:29
  • @DmitryReva create a signal handler that sends a message on a channel whenever a tag is updated, then in your management command have a task that listens on that channel and reacts to any updates, something like `while True: message = await channel_layer.receive('my_channel')` – Iain Shelvington Nov 29 '21 at 20:34
  • I am very familiar with channels, but I do not really understand how a task in management command that is already looped (socket connection to twitter) can receive a signal from channels in practice. – Dmitry Reva Nov 29 '21 at 20:42

0 Answers0