cancel
Showing results for 
Search instead for 
Did you mean: 

How to detect / manually re-run tasks that have failed after retries

jesper1
Champ in-the-making
Champ in-the-making
If you have an asynchronous task which is a JavaDelegate task, and it throws an exception, then Activiti can automatically retry it a number of times according to a schedule, as is described in section 8.7.2 of the user manual.

What happens to a process instance when the retry counter reaches zero? Does it just stay waiting at the failed task forever?

Is it possible to query for processes which have gotten into such a state, and is it possible to manually retry such a task (e.g. through an API call)?
2 REPLIES 2

martin_grofcik
Confirmed Champ
Confirmed Champ
Hi Jasper.

What happens to a process instance when the retry counter reaches zero?
retries is set to 0. You can fetch jobs with no retries left.

is it possible to manually retry such a task (e.g. through an API call)?
yes, e.g.


  /**
   * Forced synchronous execution of a job (eg. for administation or testing)
   * The job will be executed, even if the process definition and/or the process instance
   * is in suspended state.
   *
   * @param jobId id of the job to execute, cannot be null.
   * @throws ActivitiObjectNotFoundException when there is no job with the given id.
   */
  void executeJob(String jobId);

Regards
Martin

jesper1
Champ in-the-making
Champ in-the-making
Hello Martin,

Thanks for your reply. I've discovered that I can indeed query for jobs that have no retries left and that failed with an exception, using the ManagementService:


List<Job> failedJobs = managementService.createJobQuery()
        .withException().noRetriesLeft()
        .orderByJobDuedate().desc().list();
And then re-run those jobs with executeJob(). As the documentation says, this will run the job synchronously, in the thread that calls the executeJob() method.

I've seen there's also a way to set the number of retries on a job, but if I do that then Activiti is not automatically going to pick up and run the job using the job executor that I've configured the engine with.