In Quartz.NET is there a way to set a property that will only allow one instance of a Job to run?

后端 未结 4 1454
死守一世寂寞
死守一世寂寞 2020-12-24 11:44

I have a service that will run every X minutes. If that job takes longer than X minutes for some unforeseen reason I want to make sure that the trigger doesn\'t kick off a s

4条回答
  •  心在旅途
    2020-12-24 12:23

    As an update to this answer, in newer versions of Quartz.Net this is now done via an attribute "DisallowConcurrentExecution" you apply to your job implementation:

    [DisallowConcurrentExecution]
    public class MyJob : IJob  
    {
        ..
    }
    

    And for the misfire instruction, here is how to do that:

    var trigger = TriggerBuilder.Create()
        .WithSimpleSchedule(ssb => ssb.WithIntervalInMinutes(interval)
            .RepeatForever()
            .WithMisfireHandlingInstructionIgnoreMisfires()
        )
        .Build();
    

提交回复
热议问题