Quartz.NET Running Job Self-Reschedule?
c#-4.0, quartz.net, scheduled-tasks
Solution
skarist put me on the right track. Including my findings here for the next kid that runs into this.
protected override void ExecuteInternal( IJobExecutionContext jobContext )
{
// ... do work...
var tnew = new CronTriggerImpl( #nameofcurrentlyrunningjob# )
{
CronExpressionString = "my new cron string is here" ,
TimeZone = TimeZoneInfo.Utc
};
var jobNew = new JobDetailImpl( #nameofcurrentlyrunningjob# , typeof( CurrentJobType ) );
jobContext.Scheduler.RescheduleJob( new TriggerKey( #nameofcurrentlyrunningjob# ) , tnew );
}
I also added the [DisallowConcurrentExecution] attribute to the class but that's not directly related.
Problem
I have created a Quartz.NET job completely programmatically (no config file, etc). It runs on-schedule fine. The job is initialized with a cron string to run every 5 minutes. I would like to have the job change the schedule of itself based on the environment (eg errors happen over time so cron should change to 30 minutes). I am trying to determine what to write in the ``` protected override void ExecuteInternal( IJobExecutionContext context ) ``` method so the job "changes itself". Do I set something in the context.Scheduler property? Do I have to go to the Scheduler itself and terminate the job and re-create it (sounds kind of heavy handed to me though)? All ideas appreciated, thanks.