在重新启动之前让 cron 等待作业完成 [英] Have cron wait for job to finish before re-launching
问题描述
我有一个 cronjob,它每隔一分钟执行一次,通常在几秒钟内运行,但有时会持续几分钟.
I have a cronjob that executes every second minute that usually runs in seconds, but sometimes for several minutes.
如果下一分钟到来时它已经在运行,我需要 cron 不执行该命令.
I need cron to not execute the command if it's already running when the next minute comes.
这条线看起来像这样*/1 * * * * cmd
The line looks like this */1 * * * * cmd
我试过这个* * * * * ID=job1 频率=1m AFTER=job1 cmd
I have tried with this * * * * * ID=job1 FREQ=1m AFTER=job1 cmd
但没有成功.
是否可以用 cron 解决或者我必须实现锁定?
Is it possible to solve with cron or do I have to implement locking?
推荐答案
您可以制作一个名为 inProgress(或其他)的临时文件并将其存储在标准位置,并使用它与下一个工作进行通信(如果它应该运行)与否.
You can make a temp file called inProgress (or whatever) and store it in a standard place, and use this to communicate to the next job if it should run or not.
如果工作流程是这样的:
What if flow of the job goes like this:
- 检查标准进度文件
- 如果存在,退出
- 否则,创建inProgress文件
- 工作
- 删除正在进行的文件.
这篇关于在重新启动之前让 cron 等待作业完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!