Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

Custom Sling AEM Job : How Do I work with retry a job

Avatar

Level 2

Hi Team ,

 

I am working with AEM sling job , and have a situation when a job fails. how do I retry.

where do I set the count .. default is 0.

 

try {
ResourceResolver resourceResolver = utilityService.getResourceResolver();
String topic = job.getTopic();
LOGGER.info("Consuming job of topic: {}", topic);
performCustomJob(eventPath,resourceResolver);
} catch (Exception e) {
LOGGER.info("ERROR -- JOB RESULT IS FAILURE {}",e.getMessage());
result = JobResult.FAILED;

//when the  job is failed I need to retry the same step -> this How should I do.
}

 

How do i achieve it

1 Accepted Solution

Avatar

Correct answer by
Level 7

I am not sure what loop is exactly doing but yes the JobConsumer will retry automatically. We dont need to trigger Job again in case of failure. Once the job is added in JobManager.addJob() method, all work would be taken care by JobConsumer. Please refer below links for Sample code.

You need to put specific check to trigger your job only in author. 

 

https://experienceleague.adobe.com/docs/experience-manager-64/developing/platform/dev-offloading.htm...

https://redquark.org/aem/day-18-sling-jobs/

 

View solution in original post

3 Replies

Avatar

Level 7

One of the best thing about Sling Job is it guarantees Job execution and based on configuration it reties in case of failure. You do not need to right separate logic to retry. Job Consumer will retrigger automatically in case of failure.

By default Apache Sling Job Default Queue configuration has queue.retries set to 10. You can configure same for your Job by setting this property with different value.

Document : https://sling.apache.org/documentation/bundles/apache-sling-eventing-and-job-handling.html

 

Avatar

Level 2

So If I got you right, If by any reason the loop goes to catch block ,the aync job will retry itself automatically. till and it will keep trying till the count = count set.

 

and this event listener which trigger the sling job , runs just in author  per design  or do I need to put author check there??  

 

Avatar

Correct answer by
Level 7

I am not sure what loop is exactly doing but yes the JobConsumer will retry automatically. We dont need to trigger Job again in case of failure. Once the job is added in JobManager.addJob() method, all work would be taken care by JobConsumer. Please refer below links for Sample code.

You need to put specific check to trigger your job only in author. 

 

https://experienceleague.adobe.com/docs/experience-manager-64/developing/platform/dev-offloading.htm...

https://redquark.org/aem/day-18-sling-jobs/