How to avoid jobs queueing up?

1,681 views
Skip to first unread message

item...@hotmail.com

unread,
Feb 12, 2014, 3:58:14 AM2/12/14
to quar...@googlegroups.com
Hi,

Suppose I have a schedule/trigger that says to run a job every 15 seconds. If for some reason that command takes 40 seconds to complete, Quartz will fire the jobs that should have been executed. But I don't want that. I have tried to unschedule that job when it starts, but I can't re-schedule cortrectly when it stops, e.g.:

context.Scheduler.UnscheduleJob(context.Trigger.Key);
// do job work here
context.Scheduler.ScheduleJob(context.JobDetail, context.Trigger);

This just keeps firing the job rapidly in a loop. How do I accomplish this?

-- 
Werner

Markus Ursinus

unread,
Feb 12, 2014, 4:42:11 AM2/12/14
to quar...@googlegroups.com
Hi Werner!

I am not sure I understand you correctly. May be it would help to use the <DisallowConcurrentExecution> attribute in your jobclass. If you have jobs depending on the job that takes longer than expected, you have to add the jobs at the end of the job to the schedule. (so far as I know)

Cheers
Markus

Markus Ursinus

unread,
Feb 12, 2014, 5:03:14 AM2/12/14
to quar...@googlegroups.com
Hi Werner!

I am not sure i understand you right, but maybe it will solve your problem if you add the <DisallowConcurrentExecution> attribut to your jobclass.

Cheers
Markus

item...@hotmail.com

unread,
Feb 12, 2014, 6:27:06 AM2/12/14
to quar...@googlegroups.com
Hi,

No concurreny is not the issue, I only have one thread. Let me rephrase:

A Job is scheduled every 15 seconds and will offset at "00:20:00". This particular job takes 25 seconds to complete and finishes "00:20:25". You will notice that at "00:20:15" the job should have run again - it does not (I assume it would if Quartz was working with multiple threads). But the job is somehow queued up - waiting for the current job to finish.

As soon as the first one completes at 00:20:25, the one queued up is started. I don't want that. After the first job finishes at 00:20:25, the next one to start should be the one which triggers at 00:20:30. NOT the one triggered at 00:20:15. 

Makes sense?

-- 
Werner

Marko Lahma

unread,
Feb 12, 2014, 6:37:29 AM2/12/14
to quar...@googlegroups.com
What happens there is a misfire and misfire handling kicks in.

http://www.quartz-scheduler.net/documentation/quartz-2.x/tutorial/more-about-triggers.html

You need to configure your trigger's misfire instruction to be 'do nothing'.

-Marko
> --
> You received this message because you are subscribed to the Google Groups
> "Quartz.NET" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to quartznet+...@googlegroups.com.
> To post to this group, send email to quar...@googlegroups.com.
> Visit this group at http://groups.google.com/group/quartznet.
> For more options, visit https://groups.google.com/groups/opt_out.
>

item...@hotmail.com

unread,
Feb 12, 2014, 8:02:32 AM2/12/14
to quar...@googlegroups.com
Hi,

Ok, I tried this (I use a cron trigger):

var triggerConfig = CronScheduleBuilder.CronSchedule(cronExpression).WithMisfireHandlingInstructionDoNothing();

But how do I add the trigger name? Quartz seems to want that...

-- 
Werner

item...@hotmail.com

unread,
Feb 12, 2014, 8:10:03 AM2/12/14
to quar...@googlegroups.com
Update - I tried this:

var triggerConfig = TriggerBuilder.Create()
                .WithIdentity("myTrigger")
                .WithSchedule(CronScheduleBuilder.CronSchedule(cronExpression).WithMisfireHandlingInstructionDoNothing());

But still the jobs pile up?

-- 
Werner

Marko Lahma

unread,
Feb 12, 2014, 8:10:10 AM2/12/14
to quar...@googlegroups.com
Try these samples:

http://www.quartz-scheduler.net/documentation/quartz-2.x/tutorial/crontriggers.html

-Marko

On 2/12/14, item...@hotmail.com <item...@hotmail.com> wrote:
> Hi,
>
> Ok, I tried this (I use a cron trigger):
>
> var triggerConfig =
> CronScheduleBuilder.CronSchedule(cronExpression).WithMisfireHandlingInstructionDoNothing();
>
> But how do I add the trigger name? Quartz seems to want that...
>
> --
> Werner
>
> Den onsdag den 12. februar 2014 12.37.29 UTC+1 skrev Marko Lahma:
>>
>> What happens there is a misfire and misfire handling kicks in.
>>
>>
>> http://www.quartz-scheduler.net/documentation/quartz-2.x/tutorial/more-about-triggers.html
>>
>>
>> You need to configure your trigger's misfire instruction to be 'do
>> nothing'.
>>
>> -Marko
>>
>> On 2/12/14, item...@hotmail.com <javascript:>
>> <item...@hotmail.com<javascript:>>
>> > email to quartznet+...@googlegroups.com <javascript:>.
>> > To post to this group, send email to
>> > quar...@googlegroups.com<javascript:>.

item...@hotmail.com

unread,
Feb 12, 2014, 8:48:44 AM2/12/14
to quar...@googlegroups.com
Hi Marko,

It doesn't work correct. 

If I configure with WithMisfireHandlingInstructionDoNothing then it should use FireOnceNow = 1 as per documentation. But when I look at context.Trigger.MisfireInstruction in my Job, the value is 2.

Can I somehow specify the misfire value by other means when using a cron expression?

-- 
Werner

item...@hotmail.com

unread,
Feb 12, 2014, 8:52:50 AM2/12/14
to quar...@googlegroups.com
No the value configured is DoNothing = 2 so that is alright. 
Yet the misfire piles up anyway :(

-- 
Werner

Marko Lahma

unread,
Feb 13, 2014, 1:39:29 AM2/13/14
to quar...@googlegroups.com
Could provide a complete code sample for review, it would be easier
than guessing.

Thanks,

Jakub Bartkowiak

unread,
Apr 10, 2014, 6:56:43 PM4/10/14
to quar...@googlegroups.com
Please check out this sample code:

    [DisallowConcurrentExecution]
    public class MyJob : IJob
    {
        public void Execute(IJobExecutionContext context)
        {
            Console.WriteLine(context.ScheduledFireTimeUtc.Value);
            Thread.Sleep(5000);
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            var schedulerFactory = new StdSchedulerFactory();
            var scheduler = schedulerFactory.GetScheduler();

            var trigger = TriggerBuilder.Create()
                .WithSimpleSchedule(s => s
                    .WithIntervalInSeconds(1)
                    .WithMisfireHandlingInstructionIgnoreMisfires()
                    .RepeatForever());

            var job = JobBuilder.Create<MyJob>();

            scheduler.ScheduleJob(job.Build(), trigger.Build());
            scheduler.Start();

            Console.ReadLine();
        }
    }

This is the result when it runs

2014-04-10 22:48:40 +00:00
2014-04-10 22:48:41 +00:00
2014-04-10 22:48:42 +00:00
2014-04-10 22:48:43 +00:00

This means that the jobs queue up. How to modify this code so that when job is not able to run it is indeed ignored and not queued up for execution?
Reply all
Reply to author
Forward
0 new messages