I’m starting to feel desperate and really need your help with something on AEM as a Cloud Service. I’ve set up an email reminder task that operates exclusively on the author instance once a day. This task looks for something specific on a page and sends out an email.
The problem I’m facing is that it keeps sending emails twice!
Now I understand that the author server operates within a cluster and requires specific configuration/annotation. However, despite my attempts, it continues to send emails twice. On my local machine (which of course isn’t a cluster), it works correctly.
@Component(
service = Runnable.class,
property = {
SERVICE_DESCRIPTION + "=Email Reminder Task",
Scheduler.PROPERTY_SCHEDULER_RUN_ON + "=" + Scheduler.VALUE_RUN_ON_LEADER, //LEADER
Scheduler.PROPERTY_SCHEDULER_CONCURRENT + ":Boolean=false",
},
configurationPid = "com.customername.core.services.emailreminder.EmailReminderTask")
@ProviderType
@Designate(ocd = EmailReminderTaskConfig.class)
ScheduleOptions scheduleOptions = scheduler.EXPR(emailReminderTaskConfig.scheduler_expression());
scheduleOptions.name(schedulerJobName);
scheduleOptions.canRunConcurrently(false);
scheduleOptions.onLeaderOnly(true);
scheduler.schedule(this, scheduleOptions);
I also searched online, but found no proper solution. Anyone of you have a guess, why it behaves like that in the cloud?
Solved! Go to Solution.
Topics help categorize Community content and increase your ability to discover relevant content.
Just FYI: I didn't find any solution, so I refactored the implementation from org.apache.sling.commons.scheduler.Scheduler [1] to org.apache.sling.event.jobs.Job [2].
So, same solution as here: https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/aem-as-cloud-service-sched...
[1] https://sling.apache.org/documentation/bundles/scheduler-service-commons-scheduler.html
[2] https://sling.apache.org/documentation/bundles/apache-sling-eventing-and-job-handling.html
Just FYI: I didn't find any solution, so I refactored the implementation from org.apache.sling.commons.scheduler.Scheduler [1] to org.apache.sling.event.jobs.Job [2].
So, same solution as here: https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/aem-as-cloud-service-sched...
[1] https://sling.apache.org/documentation/bundles/scheduler-service-commons-scheduler.html
[2] https://sling.apache.org/documentation/bundles/apache-sling-eventing-and-job-handling.html
Hi @TrisM_ch ,
Your answer is correct. I too faced same issue when using Commons Scheduler. I explained the problem with Commons Scheduler in my article here https://medium.com/p/c5d688154f58.
Short answer, commons scheduler fires for each cluster in cloud. When cloud scales up/down, more instances run. To resolve this problem, Sling introduced Scheduled Jobs. Main difference, its persisted under /var/eventing/scheduled-jobs. This way, they prevent duplicate executions.
For AEM Cloud service, should switch to Scheduled Jobs instead of Commons Scheduler.
Hope this helps.
Views
Likes
Replies
Views
Likes
Replies