Refire quartz.net trigger after 15 minutes if job fails with exception

后端 未结 4 1474
心在旅途
心在旅途 2020-12-29 10:44

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

4条回答
  •  佛祖请我去吃肉
    2020-12-29 11:24

    // don't forget to use @PersistJobDataAfterExecution without it, the jobExecutionContext will reset the value of count.     
    
    SimpleTriggerImpl retryTrigger = new SimpleTriggerImpl();
        retryTrigger.setName("jobname");
        retryTrigger.setRepeatCount(0);
        retryTrigger.setJobKey(jobExecutionContext.getJobDetail().getKey());
        final Calendar cal = getCalendarInstance();
        cal.add(Calendar.MINUTE, 1); //retry after one minute
        retryTrigger.setStartTime(cal.getTime());
        try {
            jobExecutionContext.getScheduler().scheduleJob(retryTrigger);   // schedule the trigger
        } catch (SchedulerException ex) {
            logger.error("something went wrong", ex); 
        }
        JobExecutionException e2 = new JobExecutionException("retrying...");
        e2.refireImmediately();
        throw e2;
    

提交回复
热议问题