0

我已经编写了一些我想每小时、每天和每周运行的 django 管理命令。我正在使用 Elastic Beanstalk 并创建了一个部署代码的工作实例。有人可以帮助我如何使用弹性 beantalk 使用 crontab 运行 django 管理命令。谢谢

这是我的管理命令:

python manage.py command_name

请帮我在 .ebextensions/django.config 文件中为 crontab 编写 container_command,它将每小时安排一次命令。谢谢

有什么帮助吗?

4

1 回答 1

0

.ebextensions创建一个文件crontab.txt

# Set the cron to run with utf8 encoding
PYTHONIOENCODING=utf8

0 1 * * * root source /opt/python/current/env && nice /opt/python/current/app/manage.py command_name
# this file needs a blank space as the last line otherwise it will fail

这是一个 crontab 文件,它将在每天凌晨 1 点运行 command_name。你需要让你的路径正确,这取决于你的文件结构。

在您的一个配置文件中包括:

  02_cron_job:
    command: "cp .ebextensions/crontab.txt /etc/cron.d/my_cron_jobs && chmod 644 /etc/cron.d/my_cron_jobs"
    leader_only: true

这会将您的 cron 文件复制到 ec2 实例上的正确位置,以便作业运行。

于 2020-01-21T13:31:15.327 回答