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();
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.
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With