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?
Solved! Go to Solution.
Views
Replies
Total Likes
Do you have scheduler.concurrent property set to true? If yes can you please set it to false and see.
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:
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.
try "LEADER" (all caps).
That does the trick, thanks
Hi @Jörg_Hoh Does this solution still work? I tried few times as mentioned below. However in my case, the scheduler in AEM cloud environment always triggers twice as per the log. Am I missing anything here?
//========= Try 1 - Run on LEADER =========
@Component(service = SampleManagerScheduler.class,
configurationPid = "com.xxx.yyy.aem.core.config.SampleManagerSchedulerConfig",
property = {"scheduler.runOn=LEADER" }, immediate = true)
@Designate(ocd = SampleManagerSchedulerConfig.class)
public class SampleManagerScheduler implements Runnable {
}
//== Try 2 - Run on LEADER + Runnable.class as service ==
@Component(service = Runnable.class,
configurationPid = "com.xxx.yyy.aem.core.config.SampleManagerSchedulerConfig",
property = {"scheduler.runOn=LEADER" }, immediate = true)
@Designate(ocd = SampleManagerSchedulerConfig.class)
public class SampleManagerScheduler implements Runnable {
}
//========= Try 3 - Run on SINGLE =========
@Component(service = SampleManagerScheduler.class,
configurationPid = "com.xxx.yyy.aem.core.config.SampleManagerSchedulerConfig",
property = {"scheduler.runOn=SINGLE"}, immediate = true)
@Designate(ocd = SampleManagerSchedulerConfig.class)
public class SampleManagerScheduler implements Runnable {
}
Did you find a solution? I have the same issue.
We are not able to resolve the issue of multiple triggering of logic (from different clusters) with Apache Commons Scheduler.
However, the stated problem has been resolved after changing the implementation from org.apache.sling.commons.scheduler.Scheduler [1] to org.apache.sling.event.jobs.Job [2].
AEM as a Cloud Service Development Guidelines[3] recommend usage of approach [2] over approach [1].
[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
[3] https://docs.mktossl.com/docs/experience-manager-cloud-service/content/implementing/developing/devel...
Please find the screenshot for concurrent and cluster job configurations
Reference URL : https://sling.apache.org/documentation/bundles/scheduler-service-commons-scheduler.html#preventing-c...
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 * ? * *"
}