Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Django-Q in production

I was wondering whether I had to do anything special when using Django Q (https://django-q.readthedocs.io/en/latest/) in production.

I have a Q_Cluster setup and I can run mange.py qcluster to start all my scheduled tasks. Would I be doing the same in production?

like image 853
Justin Shakergayen Avatar asked Mar 18 '26 11:03

Justin Shakergayen


1 Answers

Systemd is a good way to manage it. You can also put the logs in a folder attached to the site. I put all my config files in the same folder as the django app, so I can keep them on the same version control. In practice it looks something like this:

/web/example/config/example-qcluster.service:

[Unit]
Description=example qcluster daemon
After=network.target

[Service]
User=<web user>
Group=www-data
RuntimeDirectory=example
RuntimeDirectoryMode=0755
PIDFile=/run/example/qcluster.pid
WorkingDirectory=/web/example
EnvironmentFile=/web/example/.env
ExecStart=/web/example/env/bin/python manage.py qcluster
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID
PrivateTmp=true
StandardOutput=file:/web/example/logs/qcluster.std.log
StandardError=file:/web/example/logs/qcluster.err.log

[Install]
WantedBy=multi-user.target

Then of course link, enable and start it:

sudo ln -s /web/example/config/example-qcluster.service /etc/systemd/system/example-qcluster.service
sudo systemctl enable example-qcluster.service
sudo systemctl start example-qcluster.service

Then, you can check it's working by tailing the log:

tail -f /web/example/logs/qcluster.std.log
like image 62
hunterbunter Avatar answered Mar 21 '26 00:03

hunterbunter



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!