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.
I wanted to run the job in random range of time, between 5 to 25 minute later after last run time, By using this answer (from @skarist) and making some changes on it and using quartz documentation, I solved my problem:
skarist put me on the right track. Including my findings here for the next kid that runs into this.
I also added the [DisallowConcurrentExecution] attribute to the class but that's not directly related.
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:
Along these lines. Hope this helps.