Expand my Community achievements bar.

SOLVED

Scheduler needs to run only once but actually runs more then once on AEM 6.5?

Avatar

Level 7

I have configured a scheduler in AEM6.5 and the idea is that it runs ONCE a night at 2AM

@Designate(ocd = TagVerificationScheduledTask.Config.class)
@Component(service = {Runnable.class})
public class TagVerificationScheduledTask implements Runnable {

@ObjectClassDefinition(name = "scheduled task that verifies tags in blog articles",
description = "A scheduled task that verifies tags in blog articles")
public @interface Config {

@AttributeDefinition(name = "Cron-job expression. Default: run every night at 2:00 AM.")
String scheduler_expression() default "0 0 2 * * ?";

 The job runs on all three instances (one author and two publishers) and I want it to run on only one instance i.E. author.
How can I configure that?

O tried @Property(name="scheduler.runOn", value="SINGLE"); but it does not work. I also tried  @AttributeDefinition(name = "Run On") String scheduler_runOn() default "SINGLE"; but that also did not work.

1 Accepted Solution

Avatar

Correct answer by
Employee Advisor

The scheduler runs independently on each AEM instance; they don't know of each other (except for the replication, but that's a different story). That means every instance thinks of itself as a SINGLE instance, which at the same time is also a Cluster LEADER.

 

That means in your setup you implement this at best on the author only (make this service only running on author using OSGI configuration, see https://cqdump.joerghoh.de/2019/10/14/how-to-use-runmodes-correctly/)

View solution in original post

7 Replies

Avatar

Community Advisor

Hi @anasustic,

I guess that you have multiple author and publish instances where the scheduler is running, possibly three instances in your case. This is why the email is sent three times at 2 AM.

Avatar

Level 7

Hi @Mahedi_Sabuj 

Thanks a lot for your reply.

I have one Author and two Publish instances. 

Is there a way to configure the job to run only once and only on one instance?

Avatar

Community Advisor

It mostly depends on your use case. You can add the OSGi configuration for the scheduler only for the author run mode, ensuring it executes just once.

Avatar

Level 7

Hi @divanshug 

Thanks a lot for your reply. I am not sure how to configure it to run only on one node (i.E. author instance) using the documentation you provided:

@Property(name="scheduler.runOn", value="LEADER");

or

@Property(name="scheduler.runOn", value="SINGLE");

 

Avatar

Correct answer by
Employee Advisor

The scheduler runs independently on each AEM instance; they don't know of each other (except for the replication, but that's a different story). That means every instance thinks of itself as a SINGLE instance, which at the same time is also a Cluster LEADER.

 

That means in your setup you implement this at best on the author only (make this service only running on author using OSGI configuration, see https://cqdump.joerghoh.de/2019/10/14/how-to-use-runmodes-correctly/)