在 cron 作业已经运行时停止其启动(甚至跨服务器)

发布于 2024-09-25 11:29:22 字数 318 浏览 0 评论 0原文

我不认为这与其他问题完全相同,但如果已经得到解答,请随时指出我的某个地方。

我正在寻找一种方法,让 cron 作业仅在尚未运行时才开始运行。例如,如果某个作业每 15 分钟运行一次,但有时需要一个小时才能运行,我不希望启动重复的进程并与原始作业正在执行的操作重叠。

在其他问题中,其他人讨论过制作一个 pid 文件来阻止作业启动重复项(或类似的策略),但我的情况有点不同。我有多台运行 cron 作业的计算机,并且我希望其中任何一台计算机上当前正在运行的进程能够阻止该作业的新实例启动。所以 pid 文件是不够的,因为它是一台机器的本地文件。

处理这种情况的最佳方法是什么?

I don't think this is an exact duplicate of other questions, but feel free to point me somewhere if it's already been answered.

I'm looking for a way to have a cron job only start running if it isn't already running. For example, if a job runs every 15 minutes but occasionally takes an hour to run, I don't want duplicate processes to start and overlap what the original job is doing.

In other questions others have talked about making a pid file that stops the job from starting duplicates (or similar strategies), but my case is a little different. I have multiple machines that run cron jobs, and I want a currently-running process on any of them to stop new instances of that job from starting. So a pid file wouldn't be enough, since it would be local to the one machine.

What is the best way of dealing with this situation?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

近箐 2024-10-02 11:29:22

共享文件夹上的 PID 文件?

A PID file over a shared folder?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文