频繁触发的 CRON Azure Web 作业是否在运行时间超过配置频率时第二次触发
Is a frequently triggered CRON Azure web job triggered a second time when it runs longer than the configured frequency
让我们假设每五分钟通过 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 to true
. 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.
让我们假设每五分钟通过 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.