Jus*_*yen 3 python django cron orm django-views
我想知道在生产中使用 Django Q ( https://django-q.readthedocs.io/en/latest/ )时是否必须做一些特殊的事情。
我有一个 Q_Cluster 设置,我可以运行 mange.py qcluster 来启动所有计划任务。我会在生产中做同样的事情吗?
小智 7
Systemd 是管理它的好方法。您还可以将日志放在附加到站点的文件夹中。我将所有配置文件放在与 django 应用程序相同的文件夹中,这样我就可以将它们保留在同一版本控制中。实际上它看起来像这样:
/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
Run Code Online (Sandbox Code Playgroud)
然后当然是链接、启用并启动它:
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
Run Code Online (Sandbox Code Playgroud)
然后,您可以通过跟踪日志来检查它是否正常工作:
tail -f /web/example/logs/qcluster.std.log
Run Code Online (Sandbox Code Playgroud)