Skip to content

Handling Job Failures

Yigit Boyar edited this page Jul 6, 2015 · 1 revision

Version 1.3.2 of the JobQueue adds ability to change a Job's priority or add delay when a job fails.

To take advantage of it, you need to override Job#shouldReRunOnThrowable(Throwable throwable, int runCount,int maxRunCount) and return a RetryConstraint. In this RetryConstraint object, you can set a new delay before retrying the Job or change the Job's priority.

Exponential Backoff

A very common way of handling failures is using an exponential backoff strategy. To make it easy, Job Queue provides a convenience method to implement it. Here is a sample shouldReRunOnThrowable method that uses exponential backoff to handle failures.

@Override
protected RetryConstraint shouldReRunOnThrowable(Throwable throwable, int runCount, int maxRunCount) {
  return RetryConstraint.createExponentialBackoff(runCount, 1000 /*base delay*/);
}