删除Elastic Beanstalk Cron

时间:2019-06-01 15:35:23

标签: amazon-web-services cron amazon-elastic-beanstalk

我正在使用弹性beantalk的cron.yaml触发定期任务。但是,如果我重新部署代码,cron将被解雇两次,效果很好。再次部署,该任务将被解雇3次,依此类推。如何删除现有的分支,以便在部署时只有一个cron实例?

2 个答案:

答案 0 :(得分:1)

答案在这里:Running a cron job in Elastic Beanstalk

Cron任务通过SQS队列实现。如果cron.yaml中的端点返回的值不是200,则触发消息将保留在队列中,并将一遍又一遍地重试。

一旦确定所有cron端点都返回200,请清除队列,冗余呼叫将停止。

答案 1 :(得分:0)

您可以使用BigDecimal定义在每个实例上运行的命令,并限定这些命令只能运行,而不必使用cron.yaml来将cron作业添加到已部署的所有EB实例中。在一个实例中使用.ebextensions

例如,

.ebextensions / 01_setup_cron.config

leader_only: true

.ebextensions / your_cron.txt

container_commands:
    01_some_cron_job:
        command: "cat .ebextensions/your_cron.txt > /etc/cron.d/your_Cron && chmod 644 /etc/cron.d/your_cron"
        leader_only: true

这只会将cron文件复制到一个实例(“ leader”实例)到* * * * * root /usr/bin/do-something.sh # Don't forget to put a blank new line at the end of the cron - cron won't work without it ,这意味着您的cron仅运行一次。