I have the following code:
IScheduler scheduler = StdSchedulerFactory.GetDefaultScheduler();
scheduler.Start();
IJobDetail job = JobBuilder.Create<EmailJob>().StoreDurably().WithIdentity("J_Email", "J_Mailing").Build();
ITrigger trigger = TriggerBuilder.Create()
.WithIdentity("MailTrigger1", "T_Mail1")
.StartNow()
.WithSimpleSchedule(x => x.WithMisfireHandlingInstructionIgnoreMisfires()
.WithIntervalInSeconds(3)
.RepeatForever())
.Build();
ITrigger triggernew = TriggerBuilder.Create()
.WithIdentity("MailTrigger", "T_Mail")
.StartNow()
.WithSimpleSchedule(x => x.WithMisfireHandlingInstructionIgnoreMisfires()
.WithIntervalInSeconds(5)
.RepeatForever())
.Build();
scheduler.ScheduleJob(job,triggernew);
scheduler.ScheduleJob(job,trigger);
I am getting the following exception:
An unhandled exception of type 'Quartz.ObjectAlreadyExistsException' occurred in Quartz.dll
Additional information: Unable to store Job: 'J_Mailing.J_Email', because one already exists with this identification.
But I have been told that you can have multiple triggers of the same JOB. Maybe I am doing something wrong?
Add the Job to the Scheduler.
Then on the creation of the triggers, use ForJob
.
The code below is tested.
IScheduler scheduler = StdSchedulerFactory.GetDefaultScheduler();
//// scheduler.DeleteJob(new JobKey("J_Email"));
IJobDetail job = JobBuilder.Create<MyConcreteJob>().StoreDurably().WithIdentity("J_Email", "J_Mailing").Build();
scheduler.AddJob(job, true /* bool replace */ ); /* Add the given IJob to the Scheduler - with no associated ITrigger. */
ITrigger trigger = TriggerBuilder.Create()
.WithIdentity("MailTrigger1", "T_Mail1")
.StartNow()
.WithSimpleSchedule(x => x.WithMisfireHandlingInstructionIgnoreMisfires()
.WithIntervalInSeconds(3)
.RepeatForever())
.ForJob(job)
.Build();
ITrigger triggernew = TriggerBuilder.Create()
.WithIdentity("MailTrigger", "T_Mail")
.StartNow()
.WithSimpleSchedule(x => x.WithMisfireHandlingInstructionIgnoreMisfires()
.WithIntervalInSeconds(5)
.RepeatForever())
.ForJob(job)
.Build();
scheduler.ScheduleJob(triggernew);
scheduler.ScheduleJob(trigger);
scheduler.Start();
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