假设每五分钟通过 CRON 触发一次作业。由于某种原因,10:00 的一次执行持续时间明显更长,例如8分钟。第二个实例是否在 10:05 触发?
如果是,确保作业作为单例运行并且不会运行两次的正确策略是什么?
最佳答案
我自己还没有测试过,但来自docs我可以找到那句话
If you use a schedule-driven task that must run as a single instance, be aware of the following:
- If the compute instance that is running the scheduler (such as a virtual machine using Windows scheduled tasks) is scaled, you will have multiple instances of the scheduler running. These could start multiple instances of the task.
- If tasks run for longer than the period between scheduler events, the scheduler may start another instance of the task while the previous one is still running.
this 中的文档中也提到了可能的解决方案部分
By default, WebJobs scale with their associated Azure Web Apps instance. However, if you want a WebJob to run as only a single instance, you can create a
Settings.job
file that contains the JSON data{ "is_singleton": true }
. This forces Azure to only run one instance of the WebJob, even if there are multiple instances of the associated web app. This can be a useful technique for scheduled jobs that must run as only a single instance.
和that部分
By default, WebJobs scale with the web app. However, you can configure jobs to run on single instance by setting the
is_singleton
configuration property totrue
. Single instance WebJobs are useful for tasks that you do not want to scale or run as simultaneous multiple instances, such as reindexing, data analysis, and similar tasks.
关于azure - 频繁触发的 CRON Azure Web 作业在运行时间超过配置的频率时是否会被第二次触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39675434/