Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Quartz.Net Trigger Scheduled Job On Demand

I have some Quartz.Net jobs which are running on a Schedule

scheduler.ScheduleJob(
new JobDetailImpl("MarkAsSolutionReminderJob", typeof(MarkAsSolutionReminderJob)),
new CalendarIntervalTriggerImpl("MarkAsSolutionReminderJobTrigger", IntervalUnit.Hour, 6));

Is it possible for me to manually trigger this Job to run when I want it to?

So it continues to run as normal, but in a specific piece of code I might want to just run it out of schedule once or twice. But it doesn't affect the scheduled job?

like image 283
YodasMyDad Avatar asked Aug 27 '15 06:08

YodasMyDad


1 Answers

Is it possible for me to manually trigger this Job to run when I want it to?

Yes, you can trigger this job as and when you need.

Use void TriggerJob(JobKey jobKey) method for this as below:

scheduler.TriggerJob(new Jobkey("MarkAsSolutionReminderJob"));

If you want to pass some data to the job while executing it on demand, you can also do that by just using another overload void TriggerJob(JobKey jobKey, JobDataMap data); of the same method as below:

Dictionary<string, string> data = new Dictionary<string, string>();
//populate dictionary as per your needs
JobDataMap jobData = new JobDataMap(data);
scheduler.TriggerJob(new Jobkey("MarkAsSolutionReminderJob"),jobData);
like image 163
Bhushan Firake Avatar answered Sep 21 '22 13:09

Bhushan Firake