@Override public JobData createJob( String jobName, long fireTime, JobData jobData ) { Assert.notNull( jobName, "jobName is required" ); Assert.notNull( jobData, "jobData is required" ); try { jobData.setJobName( jobName ); JobData job = getEm().create( jobData ); JobStat stat = getEm().create( new JobStat( jobName, job.getUuid() ) ); scheduleJob( jobName, fireTime, job.getUuid(), stat.getUuid() ); return job; } catch ( Exception e ) { throw new JobRuntimeException( e ); } }
@Override public void delayRetry( JobExecution execution, long delay ) { JobData data = execution.getJobData(); JobStat stat = execution.getJobStats(); try { // if it's a dead status, it's failed too many times, just kill the job if ( execution.getStatus() == Status.DEAD ) { getQm().deleteTransaction( jobQueueName, execution.getTransactionId(), null ); getEm().update( data ); getEm().update( stat ); return; } // re-schedule the job to run again in the future scheduleJob( execution.getJobName(), System.currentTimeMillis() + delay, data.getUuid(), stat.getUuid() ); // delete the pending transaction getQm().deleteTransaction( jobQueueName, execution.getTransactionId(), null ); // update the data for the next run getEm().update( data ); getEm().update( stat ); } catch ( Exception e ) { // should never happen throw new JobRuntimeException( String.format( "Unable to delete job data with id %s", data.getUuid() ), e ); } }