TL;DR In my django project, where do I put my "start-a-thread" code to make a thread run as soon as the django server is up?
First of all, Happy New Year Everyone! This is a question from a newbie so it might seem dumb. Thank you for your patience and help in advance!
Background Information
Recently I am writing a MQTT forwarding program which receives MQTT message. I'd like user to set some rules to handle messages to be forwarded so I chose django to build a web server. User can edit the rules themselves on the web page.
For the MQTT client I need to have a thread to receive MQTT message no matter if the user opens a webpage or not, so I cannot write it in the view.py. If I write a shell to start django server and my script separately, I am not sure how to pass the users settings from django server to my mqtt client script.
Question
1. Is there a way to start a background thread as soon as I typed python manage.py runserver
?
2. One of the user settings is the MQTT server host, so once the user change this entry on the webpage, the background MQTT client should restart and connect to the new host. Is there any ways to achieve that?
I did some research and some likely solutions I found were django-background-tasks
or Celery
but I am not sure those are the right way, and I think this problem is too small to import another heavy module to deal with. Please give me some advice! If you are unclear about anything feel free to ask me!
Thank you again!