Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

quartz trigger builder startnow not firing the trigger during the start

i am tring to use quartz builder for creating a cron trigger and trying to give the startnow instruction. but the trigger is not starting instead it is starting only after completing the given time interval. can someone help me to start the trigger during the starting the server.i am using plain quartz and no springs.

Trigger trigger = newTrigger()
        .withIdentity(SchedulerConstants.TRIGGER_CLARITY,SchedulerConstants.QI_GROUP)
        .withSchedule(cronSchedule("0 0/60 * * * ?").withMisfireHandlingInstructionDoNothing())
        .startNow()
        .build();
like image 315
syam Avatar asked Dec 20 '22 23:12

syam


2 Answers

There wont be any effect of calling startNow() on a CronTrigger as it triggers the job based on cron expression supplied unlike time based SimpleTrigger.

Your cron expression tells Quartz to run every 60 mins starting 0th minute of ever hour. Unless you start the scheduler at exactly 0th min, you willnot see startNow effect.

Hope this is clear to you.

Refer Quartz CronTrigger tutorials/documentation for more details.

like image 129
devThoughts Avatar answered Jan 14 '23 04:01

devThoughts


You can add a second trigger to your job with StartNow. I think this would work for you assuming you had a job class called SomeJob.

   var schedulerFactory = new StdSchedulerFactory();
   var scheduler = schedulerFactory.GetScheduler();
   scheduler.Start();

   IJobDetail job = JobBuilder.Create<SomeJob>()
            .WithIdentity("job1", SchedulerConstants.QI_GROUP)
            .Build();        
   Trigger trigger = newTrigger()
            .withIdentity(SchedulerConstants.TRIGGER_CLARITY,SchedulerConstants.QI_GROUP)
            .withSchedule(cronSchedule("0 0/60 * * * ?").withMisfireHandlingInstructionDoNothing())
            .build();
   scheduler.ScheduleJob(job, trigger);

   IJobDetail job2 = JobBuilder.Create<SomeJob>()
            .WithIdentity("job2", SchedulerConstants.QI_GROUP)
            .Build();        
   Trigger trigger2 = newTrigger()
            .withIdentity("trigger2",SchedulerConstants.QI_GROUP)
            .StartNow()
            .build();
   scheduler.ScheduleJob(job2, trigger2);
like image 40
DocHammoc Avatar answered Jan 14 '23 04:01

DocHammoc