Task in AEM as a Cloud Service (only on author) is running twice
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.
Attempt #1: nok
@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)
Attempt #2: nok
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?