Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Execute Job only after previous one has been executed

Tags:

quartz.net

I have a job that is scheduled to execute every minute:

        var trigger = TriggerBuilder.Create().
            StartNow().
            WithSimpleSchedule(x => x.WithIntervalInMinutes(1).RepeatForever()).
            Build();

But sometimes it takes for the job more than one minute to be executed. So the next job is started till the previous is finished and it results into some conflicts.

Is it possible to tell to Quartz.Net schedule to run a job every minute but only if the previous job has already finished?

like image 354
SiberianGuy Avatar asked Oct 24 '14 04:10

SiberianGuy


1 Answers

If you're using Quartz 2.x, you need to decorate your job class with DisallowConcurrentExecutionAttribute. Something like the below:

[Quartz.DisallowConcurrentExecutionAttribute()]
public class HelloJob : IJob
...

This is addressed in the FAQ under "How do I keep a Job from firing concurrently?" http://www.quartz-scheduler.net/documentation/faq.html

like image 68
Jongyu Lin Avatar answered Sep 28 '22 03:09

Jongyu Lin