【问题标题】:Using Django-Q in production在生产中使用 Django-Q
【发布时间】:2021-03-22 07:24:49
【问题描述】:

我想知道在生产中使用 Django Q (https://django-q.readthedocs.io/en/latest/) 时是否需要做一些特别的事情。

我有一个 Q_Cluster 设置,我可以运行 mange.py qcluster 来启动我所有的计划任务。我会在生产中做同样的事情吗?

【问题讨论】:

  • 我会这么认为,除非另有明确说明。
  • 如何在生产环境中运行 manage.py 命令?
  • @TD1 如果您使用 linux 服务器进行部署,您可以使用 cron 作业。我在那个项目中使用了 heroku,并且有一个调度程序扩展。
  • 谢谢@JustinShakergayen。我最终在 linux 上使用 systemd 守护进程。
  • @TD1 很高兴听到你想通了

标签: python django orm django-views cron


【解决方案1】:

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

然后当然是链接,启用并启动它:

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

然后,您可以通过跟踪日志来检查它是否正常工作:

tail -f /web/example/logs/qcluster.std.log

【讨论】:

    猜你喜欢
    • 2022-11-22
    • 1970-01-01
    • 2013-08-21
    • 1970-01-01
    • 2015-09-29
    • 2017-03-20
    • 1970-01-01
    • 2013-05-30
    • 1970-01-01
    相关资源
    最近更新 更多