我需要使用以下命令按计划更新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=$2Crontab:
MAILTO=webmaster@website 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命令
发布评论