cancel
Showing results for 
Search instead for 
Did you mean: 

Retry failed job and duedate/lockExpirationDate

mapor
Champ in-the-making
Champ in-the-making
Hello,

I'm trying to write a class in order to retry failed job with a delay, in my command i use the following lines :


public Object execute(CommandContext commandContext) {
     if(this.jobId==null){
        LOGGER.error("no job id given");
        throw new IllegalArgumentException();
     }
      JobEntity job = Context
      .getCommandContext()
      .getJobEntityManager()
      .findJobById(jobId);
    job.setLockOwner(null);
    Date date = Calendar.getInstance().getTime();
    date.setTime(date.getTime()+TEN_MN_IN_MS);
   
    job.setLockExpirationTime(date);
    job.setDuedate(date);
    if(LOGGER.isDebugEnabled()){
       LOGGER.debug("Job "+jobId+" has been delayed to "+date.getTime());
    }

    if(exception != null) {
      job.setExceptionMessage(exception.getMessage());
      job.setExceptionStacktrace(getExceptionStacktrace());
    }
    return null;
  }


However i can still see a value in lock owner in the jobs that should not have one anymore, and duedate is only update for timer entites, not message.

The purpose is to retry any kind of job with a delay like 10mn or 1h any amount of times it's required (due to external systems not very friendly…) .

I know about a JIRA that solved the case by patching activiti but i'm not allowed to patch Activiti and as it has been said in the JIRA, it should be enough to replace a FailedJobCommandFactory in order to do that, but it doesn't work.

Any idea of what doesn't work or other way to handle that are welcome.
24 REPLIES 24

mapor
Champ in-the-making
Champ in-the-making
I think i find the problem : i really set the dueDate but the DueDate is not update in the SQL Query generated (see logs attached with this post).

-> update ACT_RU_JOB SET REV_ = ?, LOCK_EXP_TIME_ = ?, LOCK_OWNER_ = ?, RETRIES_ = ?, EXCEPTION_STACK_ID_ = ?, EXCEPTION_MSG_ = ? where ID_= ? and REV_ = ?

jbarrez
Star Contributor
Star Contributor
Good find. Indeed - you Job is a Message … and messages don't have a due date update:

<code>
<update id="updateMessage" parameterType="org.activiti.engine.impl.persistence.entity.MessageEntity">
    update ${prefix}ACT_RU_JOB
    <set>
       REV_ =  #{revisionNext, jdbcType=INTEGER},
       LOCK_EXP_TIME_ = #{lockExpirationTime, jdbcType=TIMESTAMP},
       LOCK_OWNER_ = #{lockOwner, jdbcType=VARCHAR},
       RETRIES_ = #{retries, jdbcType=INTEGER},
       EXCEPTION_STACK_ID_ = #{exceptionByteArrayRef, typeHandler=ByteArrayRefTypeHandler},
       EXCEPTION_MSG_ = #{exceptionMessage, jdbcType=VARCHAR}
    </set>
    where ID_= #{id, jdbcType=VARCHAR}
      and REV_ = #{revision, jdbcType=INTEGER}
  </update>
</code>

So im wondering if the due date should be applied to this too (like for times)…. I don't see how it would break anything …

jbarrez
Star Contributor
Star Contributor
Had a think about it, and figured it makes sense to allow.
Hence, it's been added on master: https://github.com/Activiti/Activiti/commit/0a75640297717be4d28c51c1a5dc5af2bbc2db87

mapor
Champ in-the-making
Champ in-the-making
Thanks.

How should i integrate it ? Should i update activiti's version in maven pom and that's it ? Or should i wait for the next release ?

trademak
Star Contributor
Star Contributor
We expect to release a new Activiti version before the end of this month. You can also get the latest Activiti version from Github and build it yourself locally.

Best regards,