AnsweredAssumed Answered

Change number of retries and interval in job fail retry

Question asked by heldergr on Oct 16, 2013
Latest reply on Jun 15, 2016 by martin.grofcik
Hi all,

Im trying to change the default number of retries and the invertal between the retries of a failing job but I could not have success. My attempt is based on the what was suggested in the following links:


I created customized failed job command factory and command as listed below. Im trying to change the interval using the method setDueDate in the Job, but it always run immediately. 

So I have two doubts.
The first is what is the correct strategy to change the interval between retries? Which method in Job (or another class) should I use?
The second question is how can I change the number of retries to 5, for example? I know I can set the retries in the job, but I should know when the command is executing the first time to set the remaining number of retries. It looks a very basic question, but I could not have an anwser yet.

Process definition:

   <process id="ProcessoJobRetry" name="Processo Job Retry"

      <startEvent id="theStart" />
      <sequenceFlow sourceRef='theStart' targetRef='javaService' />

      <serviceTask id="javaService" name="My Java Service Task"
         activiti:async="true" />
      <sequenceFlow sourceRef='javaService' targetRef='theEnd' />

      <endEvent id="theEnd" />

My job (it only forces a fail):

public class JobRetryJavaDelegate implements JavaDelegate {

   public void execute(DelegateExecution execution) throws Exception {
      throw new NullPointerException();

My failed job command factory:

public class MyFailedJobCommandFactory extends DefaultFailedJobCommandFactory {

   public Command<Object> getCommand(String jobId, Throwable exception) {
      return new MyDecrementJobRetriesCmd(jobId, exception);

My failed job command:

public class MyDecrementJobRetriesCmd implements Command<Object> {

   protected String jobId;
   protected Throwable exception;

   public MyDecrementJobRetriesCmd(String jobId, Throwable exception) {
      this.jobId = jobId;
      this.exception = exception;

   public Object execute(CommandContext commandContext) {

      JobEntity job = Context.getCommandContext().getJobEntityManager()
      job.setRetries(job.getRetries() - 1);
      if (exception != null) {

      JobExecutor jobExecutor = Context.getProcessEngineConfiguration()
      MessageAddedNotification messageAddedNotification = new MessageAddedNotification(
      TransactionContext transactionContext = commandContext

      return null;

   private Date calculateNextDueDate(Integer secondsDelay) {
      GregorianCalendar gregorianCalendar = new GregorianCalendar();
      gregorianCalendar.add(Calendar.SECOND, secondsDelay);
      return gregorianCalendar.getTime();
   private String getExceptionStacktrace() {
      StringWriter stringWriter = new StringWriter();
      exception.printStackTrace(new PrintWriter(stringWriter));
      return stringWriter.toString();

Thanks in advance!