如果当前作业未完成,Cron会启动新作业吗? [英] Will Cron start a new job if the current job is not complete?

查看:148
本文介绍了如果当前作业未完成,Cron会启动新作业吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

我有一个 cron 工作,可能需要2分钟或可能需要5小时。
我需要确保此作业始终执行。

I'm having a cron job that do work that may take 2 mins or may take 5 hours. I need to make sure that this job is always executed.

我的问题是

在上一个操作完成后,它会启动,还是会同时运行,如果我设置为每分钟执行一次,那么数据库是否会运行?

Will it start after the previous one is done or will they both run at the same time and mess up the database if i set it to execute every minute ?

推荐答案

我建议将其记录在数据库中。我将记录脚本启动时和任务成功完成。
脚本也应该更新db中的记录 - 比如每5分钟一次 - 我还在运行。

I would suggest to record it in database. I would record when script started and if task was successfully finished. The script should also update record in db - something like every 5 mins - I am still running.

当新作业开始时,它应该检查所有以前的任务完成或最后一次更新是更多然后分钟(?)以前,如果是然后运行,没有然后退出。

When new job is started, it should check if all previous tasks are finished or last update was more then then minutes (?) ago, if yes then run, no then exit.

这样你就知道以前的脚本正在运行或者如果它死了,未完成并且未更新10分钟的作业将被标记为已完成。

This way you know that previous script is running or if it died, job which is not finished and hasn't been updated for 10 minutes is going to be marked as finished.

我应该提到这个解决方案可能更好当你有多个服务器,任务可以触发任何他们。

I should mention this solution might be better than flock when you have multiple servers and task can be triggered on any of them.

这篇关于如果当前作业未完成,Cron会启动新作业吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆