Refire quartz.net trigger after 15 minutes if job fails with exception
Actually, its not necessary to create a new JobDetail like described by LeftyX. You can just schedule a new trigger that is connected to the JobDetail from the current context.
public void Execute(JobExecutionContext context) {
try {
// code
} catch (Exception ex) {
SimpleTriggerImpl retryTrigger = new SimpleTriggerImpl(Guid.NewGuid().ToString());
retryTrigger.Description = "RetryTrigger";
retryTrigger.RepeatCount = 0;
retryTrigger.JobKey = context.JobDetail.Key; // connect trigger with current job
retryTrigger.StartTimeUtc = DateBuilder.NextGivenSecondDate(DateTime.Now, 30); // Execute after 30 seconds from now
context.Scheduler.ScheduleJob(retryTrigger); // schedule the trigger
JobExecutionException jex = new JobExecutionException(ex, false);
throw jex;
}
}
This is less error prone than creating a new JobDetail. Hope that helps.
I think that the right answer is to use JobListener to retry a job as described here: http://thecodesaysitall.blogspot.cz/2012/03/quartz-candy-part-1.html.
You separate retry logic from Job itself in this solution, so it can be reused.
If you implement retry logic in job as suggested in another replies here, it must be implemented again in every job.
Edit: According to the Ramanpreet Singh note better solution can be found here: https://blog.harveydelaney.com/quartz-job-exception-retrying/