AEM as Cloud Service - Scheduler Trigger Twice | Community
Skip to main content
New Participant
February 3, 2022
Solved

AEM as Cloud Service - Scheduler Trigger Twice

  • February 3, 2022
  • 3 replies
  • 6137 views

I have created a scheduler which looks for the content fragment and updates its properties once a day. The job works okey on local cloud sdk. But on cloud environment; scheduler is getting activated twice and as it tries to update same content fragment it throws "javax.jcr.InvalidItemStateException: OakState0001: Unresolved conflicts"  error.

 

The code looks like this 

 

@Component(immediate = true, service = Runnable.class,property = {
"scheduler.expression=0 0 2 ? * *"
})
public class TestScheduledTask implements Runnable {

How can i make job trigger only once on cloud environment? 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

3 replies

Mani_kumar_
New Participant
February 3, 2022

Please find the screenshot for concurrent and cluster job configurations

 

Reference URL : https://sling.apache.org/documentation/bundles/scheduler-service-commons-scheduler.html#preventing-concurrent-execution-1

New Participant
February 4, 2022

I also added "scheduler.concurrent=false" property. Same as "runOn=Leader" property, my scheduled job do not trigger even once. I checked my job via Developer Console and it's state is Active as below.

 

Did i miss something?

 {
"name": "com.*******.core.schedulers.TestScheduledTask",
"bundle": {
"bundleID": 586,
"symbolicName": "*******.core"
},
"state": "active",
"defaultState": "enabled",
"activation": "immediate",
"configurationPolicy": "optional",
"serviceID": 5391,
"services": [],
"references": [ ... ]
"properties": {
"component.id": 3296,
"component.name": "com.*******.core.schedulers.TestScheduledTask",
"scheduler.concurrent": "false",
"scheduler.expression": "0 */30 * ? * *"
}

 

joerghoh
Employee
February 3, 2022

In AEM as a Cloud Service you have a cluster of authors, typically 2 or more instances. So you need to restrict this job to run only on one node.

The easiest way to achieve this is specifying it as an additional property:

@Component(immediate = true, service = Runnable.class,property = {
"scheduler.expression=0 0 2 ? * *",
"scheduler.runOn=Leader"
})
public class TestScheduledTask implements Runnable {

 

See: 

https://sling.apache.org/documentation/bundles/scheduler-service-commons-scheduler.html#scheduling-the-job-just-once-in-a-cluster-1

New Participant
February 4, 2022

Thank you for your reply. I added the property runOn=Leader on my schedular and deploy it. Unfortunately the job is not even trigger once now. The cloud error logs contains below   

 

org.apache.sling.commons.scheduler.impl.QuartzScheduler Job Registered Service.5318 (com.*********.core.schedulers.TestScheduledTask@81a865c) is scheduled to run on specific Sling Instances. This feature is deprecated. Please don't use it anymore.

ibishika
New Participant
February 3, 2022

Do you have scheduler.concurrent property set to true? If yes can you please set it to false and see.