Custom Sling AEM Job : How Do I work with retry a job | Community
Skip to main content
Level 2
August 4, 2022
Solved

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

  • August 4, 2022
  • 1 reply
  • 2530 views

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

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Sachin_Arora_

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.html?lang=en

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

 

1 reply

Sachin_Arora_
Community Advisor
Community Advisor
August 4, 2022

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

 

Level 2
August 4, 2022

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??  

 

Sachin_Arora_
Community Advisor
Sachin_Arora_Community AdvisorAccepted solution
Community Advisor
August 4, 2022

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.html?lang=en

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