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
Sorry i forgot the link to the referenced JIRA : https://jira.codehaus.org/browse/ACT-1046

trademak
Star Contributor
Star Contributor
This issue is fixed in Activiti 5.10. Are you using an older version? I would really recommend to upgrade to a more recent version.

Best regards,

mapor
Champ in-the-making
Champ in-the-making
I'm using the version 5.15.1.

trademak
Star Contributor
Star Contributor
Hi,

How did you plugin your custom job functionality in the Activiti Engine?

Best regards,

mapor
Champ in-the-making
Champ in-the-making
With psring injection.

The class  implements Command<Object> and FailedJobCommandFactory by returning a new instance of himself with the given parameter.

<code>
<property name="failedJobCommandFactory">
          <bean class="com.alstom.userportal.workflow.bean.RetryJobExecutor" />
     </property>
</code>

<code>
@Override
public Command<Object> getCommand(String arg0, Throwable arg1) {
  return new RetryJobExecutor(arg0, arg1);
}
</code>

With a breakpoint i'm sure that i pass in the execute method but still data in database are not fullfilled / resetted (lockOwner) correctly.

trademak
Star Contributor
Star Contributor
In your implementation I see the following line:

<blockcode>
Context.getCommandContext()
</blockcode>

You already have a command context available, so you should be using that one. Don't know if this solves the issue though. Let me know if the issue is still there and we'll do some testing for it.

Best regards,

mapor
Champ in-the-making
Champ in-the-making
Still doesn't work, the columns due_date and lock_exp_time are still empty even when the following code is executed :

<java>
  job.setLockExpirationTime(date);
  job.setDuedate(date);
</java>

Job status in the database :
<code>
"525";15;"message";"";"";TRUE;"523";"409";"AppstoreRequest:5:408";0;"528";"Error while evaluating expression: #{appstoreDelegate.createITSM7Request(requestDelegated, computerId, packageId)}";"";"";"async-continuation";"";"''"

</code>

Maybe my change are absolutely not persisted while the exception message have already been set by something else somewhere ? 

With breakpoints i'm sure that my RetryJobExecutor is executed and not the DecrementJobRetriesCmd.

mapor
Champ in-the-making
Champ in-the-making
Any news ? Or should i go for a custom cron job that retry job outside the context of activiti ?

jbarrez
Star Contributor
Star Contributor
No, im quite puzzled. it could indeed be that the exception takes over and removes your changes.

Is there any chance you can put your custom job factory in a small unit test that demonstrates the issue?