Hangfire-防止同一作业的多个入队 [英] Hangfire - Prevent multiples of the same job being enqueued
本文介绍了Hangfire-防止同一作业的多个入队的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
作业1 按计划每5分钟运行一次,大约需要1分钟才能完成.
Job 1 is scheduled to run every 5 minutes, and takes ~1 minute to complete.
大量工作堆积如山,工作1 需要15分钟才能运行.
A lot of work piles up and Job 1 takes 15 minutes to run.
现在有3个职位1 正在同时处理-我不希望这样.
如何防止作业1 再次添加到队列中?
There are now three Job 1's being processed concurrently - I don't want this.
How do I prevent Job 1 being added to the queue again if it is already there?
是否有Hangfire设置,还是需要手动轮询作业状态?
Is there Hangfire setting, or do I need to poll job statuses manually?
推荐答案
You can use DisableConcurrentExecution attribute to prevent multiple executions of a method concurrently. Just put this attribute above your method -
[DisableConcurrentExecution(timeoutInSeconds: 10 * 60)]
public void Job1()
{
// Metohd body
}
这篇关于Hangfire-防止同一作业的多个入队的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文