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
Solved! Go to Solution.
Views
Replies
Total Likes
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://redquark.org/aem/day-18-sling-jobs/
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
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??
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://redquark.org/aem/day-18-sling-jobs/
Views
Like
Replies