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.
While I haven't used Quartz.NET I have used Quartz in Java projects, and I would think they are similar. I have implemented a solution similar to what you describe. In the executeInteral method you have access to the jobexecution context. Basically it involves the creation of a new trigger and then reschedule the job (rescheduleJob). So when the condition arise you would do something like:
protected void ExecuteInternal( IJobExecutionContext context ) {
// ... some code
if (the_condition) {
// figure out startTime
// figure out endTime
// figure out repeat time
// figoure out repeatInterval
Trigger trigger = new SimpleTrigger("OurNewTrigger","GROUP_NAME", context.getJobDetail().getName(),context.getJobDetail().getGroup(), startTime, endTime,repeatTime,repeatInterval);
context.getScheduler().rescheduleJob("OurNewTrigger","GROUP_NAME",trigger);
}
// ... some more code
}
Along these lines. Hope this helps.
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