在重新启动之前,cron等待作业完成 [英] Have cron wait for job to finish before re-launching
本文介绍了在重新启动之前,cron等待作业完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个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 FREQ = 1m AFTER = job1 cmd
I have tried with this * * * * * ID=job1 FREQ=1m AFTER=job1 cmd
但无法成功。
实现锁定
推荐答案
您可以创建一个名为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.
如果工作流程如下:
- 检查标准inProgress
文件 - 如果存在,请退出
- ,创建inProgress文件
- 执行工作
- 删除inProgress文件。
- Check for a standard inProgress file
- If it exists, quit
- Else, create inProgress file
- Do work
- Delete inProgress file.
这篇关于在重新启动之前,cron等待作业完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文