Refire quartz.net trigger after 15 minutes if job fails with exception
quartz.net, triggers
Solution
I think the only option you have is to trap the error and tell Quartz.net to refire immediately:
public class MyJob : IJob
{
public void Execute(JobExecutionContext context)
{
var service = new service();
try
{
service.Download();
}
catch (Exception ex)
{
JobExecutionException qe = new JobExecutionException(ex);
qe.RefireImmediately = true; // this job will refire immediately
throw qe;
}
}
}
You can find some info here and here.
UPDATE:
I did some tests and it seems that you can schedule a new trigger inside an executing job. You can try something like this:
public class MyJob : IJob
{
public void Execute(JobExecutionContext context)
{
var service = new service();
try
{
service.Download();
}
catch (Exception ex)
{
JobExecutionException qe = new JobExecutionException(ex);
// qe.RefireImmediately = true; // this job will refire immediately
// throw qe;
OnErrorScheduleJob(context);
}
}
private void OnErrorScheduleJob(JobExecutionContext context)
{
var jobOnError = context.Scheduler.GetJobDetail("ONERRORJOB", "ERROR");
if (jobOnError == null)
{
JobDetail job = new JobDetail("ONERRORJOB", "ERROR", typeof(MyJob));
job.Durable = false;
job.Volatile = false;
job.RequestsRecovery = false;
SimpleTrigger trigger = new SimpleTrigger("ONERRORTRIGGER",
"ERROR",
DateTime.UtcNow.AddMinutes(15),
null,
1,
TimeSpan.FromMinutes(100));
context.Scheduler.ScheduleJob(job, trigger);
}
}
}
Problem
I have searched for an answer on how to retrigger a job after a ceratin amount of time, if the job throws an exception. I cannot see any simple way of doing this. if I set my trigger up like this: ``` JobDetail job = new JobDetail("Download catalog", null, typeof(MyJob)); job .Durable = true; Trigger trigger= TriggerUtils.MakeDailyTrigger(12, 0); trigger.StartTimeUtc = DateTime.UtcNow; trigger.Name = "trigger name"; scheduler.ScheduleJob(job , trigger); ``` And MyJob look like this: ``` public class MyJob : IJob { public void Execute(JobExecutionContext context) { var service = new service(); try { service.Download(); } catch (Exception) { throw; } } } ``` how do I make the trigger to refire/retrigger after there is gone 15 minutes if the service.Download() call throws some sort of Exception?