How to prevent multiple quartz work

I am using quartz.net 2.3 Jobs are marked with the DisallowConcurrentExecution attribute. When a task is started manually using TriggerJob, it does not start, if it is already running, this is normal. But it starts immediately after the completion of the previous run. Is it possible to prevent future execution if it was started when the work is in progress?

+4
source share
3 answers

Yes. You can get all the triggers for the task, compare them with the one that is running, and after they were scheduled after it, sort the task (the triggers will be deleted).

So, from your work:

public void Execute(IJobExecutionContext context)
{
    var currentlyExecutingTrigger = context.Trigger;
    var currentlyExecutingJobkey = context.JobDetail.Key;

    var newTriggers = context.Scheduler.GetTriggersOfJob(key);

    //if trigger was scheduled after currently executing trigger
    foreach (var newTrigger in newTriggers)
    {
        if (newTrigger.StartTimeUtc >= trigger.StartTimeUtc)
        {
            //delete it
            context.Scheduler.UnscheduleJob(newTrigger.Key);
        }
    }
}
+1
source

?

Quartz.NET 2.x

IJob, [DisallowConcurrentExecution]. API DisallowConcurrentExecutionAttribute.

+1

I think you are looking for this:

myJobTrigger.MisfireInstruction = MisfireInstruction.CronTrigger.DoNothing;  

I have not tried, but it looks like it works well with the DisallowConcurrentExecution attribute

fooobar.com/questions/163541 / ...

0
source

Source: https://habr.com/ru/post/1584190/


All Articles