Django Celery安排manage.py命令

编程入门 行业动态 更新时间:2024-10-26 10:31:41
本文介绍了Django Celery安排manage.py命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我需要使用以下命令按计划更新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 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命令

本文发布于:2023-10-22 22:20:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1518894.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:命令   Celery   Django   py   manage

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!