Expand my Community achievements bar.

SOLVED

AEM Job Scheduler is running multiple times on AEM cloud

Avatar

Level 2

Hi,

As the title stated, A job scheduler I created that was deployed on AEM cloud is running multiple times. No issues on my local only on AEM cloud this happens.

 

Below is the code snippet of my scheduler:

@component(immediate = true,
           service = SchedulerJob.class,
           property = {"scheduler.runOn=LEADER",
                       "scheduler.concurrent=false"})
public class SchedulerJob implements Runnable {

    @activate
    protected void activate() {
        // activate logic below
    }

    @deactivate
    protected void deactivate() {
        // deactivate logic below
    }

    @Override
    public void run() {
        // run logic below
    }

    private void scheduleJob(String jobExpression) {
        // scheduleJob logic below
    }

    private void unscheduleJob() {
        // unscheduleJob logic below
    }
}

To some I've seen they were able to resolved their issue by adding the props "runOn and concurrent" which I already added to my code but I'm still encountering the issue. Any help is greatly appreciated, thanks!

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

@zmdeluyas : I think it is called Leader instance On AEMaaCS author. Since you already have scheduler.runOn=LEADER, it should be running on the leader author instance.

I did not see any scheduler config in your code, is it meant to execute at a specific time? If yes, can you share what is frequency (maybe share your cron expression etc)

Please try with the changes suggested and see if it works.

View solution in original post

6 Replies

Avatar

Community Advisor

@zmdeluyas : Is this happening on AEMaaCS author instance? 

Please see this reference : https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/aem-cloud-is-scheduler-run...
Text taken from above reference.

By default the scheduler runs on all instances, and that's not different at all to any on-prem and AMS based environment. For clustered instances (like the authoring instances in AEM as a Cloud Service) you have the option to run it only on the master.

 

Avatar

Community Advisor

There is another reference where it says to have scheduler.runOn=LEADER which you are already doing.

https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/aem-as-cloud-service-sched...

Also, any specific reason you have specified service = SchedulerJob.class instead of service = Runnable.class

You can try changing this as well and see if it works.

thanks.

 

Avatar

Level 2

No particular reason, I just based this code on the existing ones I've seen on my project but I'll try changing it to Runnable.class and Yes this is happening on AEMaaCS author instance. Also how do we set the schedulers to run on master only? 

Avatar

Correct answer by
Community Advisor

@zmdeluyas : I think it is called Leader instance On AEMaaCS author. Since you already have scheduler.runOn=LEADER, it should be running on the leader author instance.

I did not see any scheduler config in your code, is it meant to execute at a specific time? If yes, can you share what is frequency (maybe share your cron expression etc)

Please try with the changes suggested and see if it works.

Avatar

Community Advisor

Hi @zmdeluyas ,


If your job is running multiple time then can you can try using below , have just changed the sequence of property and added runOn on single instance in clustered environment.

property = {"scheduler.concurrent=false", "scheduler.runOn=SINGLE"}

 
Thanks
Tarun

Avatar

Administrator

@zmdeluyas Did you find the suggestions from users helpful? Please let us know if more information is required. Otherwise, please mark the answer as correct for posterity. If you have found out solution yourself, please share it with the community.



Kautuk Sahni