Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add new job or update the trigger for existing job in the Quartz.Net?

I am getting job details like start time and effective date from the database and on the basis of the job details, I am creating the job but what if I have got another entry for new job or the start time has been changed for the scheduled job, so how new job will be added in the job scheduler or new start time will be changed in the scheduler.

I am using C#.net.

like image 897
user1301587 Avatar asked Apr 25 '12 18:04

user1301587


1 Answers

I do not know if it was not possible to update the existing trigger in Quartz in the previous version, but it is possible to update the trigger in the newer version (as of 2.* ).

The update could be achieved as follows (adapted for Quartz.net);

// retrieve the trigger
Trigger oldTrigger = sched.GetTrigger(new TriggerKey("oldTrigger", "group1"));

// obtain a builder that would produce the trigger
TriggerBuilder tb = oldTrigger.GetTriggerBuilder();

// update the schedule associated with the builder, and build the new trigger
// (other builder methods could be called, to change the trigger in any desired way)
Trigger newTrigger = tb.WithSimpleSchedule(x => x.WithIntervalInSeconds(10).WithRepeatCount(10))
    .Build();

sched.RescheduleJob(oldTrigger, newTrigger);

Source

like image 87
Ad Infinitum Avatar answered Oct 06 '22 22:10

Ad Infinitum