Django Celery安排manage.py命令 [英] Django Celery Scheduling a manage.py command
问题描述
我需要使用以下命令按计划更新solr索引:
I need to update the solr index on a schedule with the command:
(env)$ ./manage.py update_index
我浏览了Celery文档并找到了有关排程的信息,但还无法进行查找在日程表上和virtualenv中运行django管理命令的方法。在常规的cron上运行会更好吗?如果是这样,我将如何在virtualenv中运行它?有人有经验吗?
I've looked through the Celery docs and found info on scheduling, but haven't been able to find a way to run a django management command on a schedule and inside a virtualenv. Would this be better run on a normal cron? And if so how would I run it inside the virtualenv? Anyone have experience with this?
谢谢您的帮助!
推荐答案
要从cron作业定期运行命令,只需将命令包装在加载virtualenv的bash脚本中。例如,以下是我们运行manage.py命令的操作:
To run your command periodically from a cron job, just wrap the command in a bash script that loads the virtualenv. For example, here is what we do to run manage.py commands:
django_cmd.sh:
django_cmd.sh:
#!/bin/bash
cd /var/www/website/
source venv/bin/activate
/var/www/website/manage.py $1 --settings=$2
Crontab:
MAILTO=webmaster@website.com
SETTINGSMODULE=website.settings_prod
5 * * * * /var/www/website/django_cmd.sh update_index $SETTINGSMODULE >> /dev/null
0 10 * * * /var/www/website/django_cmd.sh update_accounts $SETTINGSMODULE
这篇关于Django Celery安排manage.py命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!