Refire quartz.net trigger after 15 minutes if job fails with exception -
i have searched answer on how retrigger job after ceratin amount of time, if job throws exception. cannot see simple way of doing this.
if set trigger 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 this:
public class myjob : ijob { public void execute(jobexecutioncontext context) { var service = new service(); try { service.download(); } catch (exception) { throw; } } } how make trigger refire/retrigger after there gone 15 minutes if service.download() call throws sort of exception?
i think option have trap error , tell quartz.net 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; // job refire throw qe; } } } you can find info here , here.
update:
i did tests , seems can schedule new trigger inside executing job.
can try 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; // job refire // 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); } } }
Comments
Post a Comment