Run Scheduler on specific duration in AEMaaCS | Community
Skip to main content
Level 2
December 16, 2024
Solved

Run Scheduler on specific duration in AEMaaCS

  • December 16, 2024
  • 3 replies
  • 786 views

Hello guys ,

 

I need help regarding a requirement to run a scheduler to perform a common query on a path each day , every month  . For eg --

 

1) run query on path1  -- day 1 on every month

2) run query on path2  -- day 2 on every month

3) run query on path3  -- day 3 on every month

 

I am following this blog for scheduler development -- https://redquark.org/aem/day-16-schedulers-in-aem . 

 

 

Sincerely,

Rahul kumar

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

Hi @newbie34 
Let me start by asking you, where is your bottleneck ? Is it because you need to make it work in AEMaaCS ?

 

Assuming it is, I will advise you to start with this article: https://cqdump.joerghoh.de/2022/06/20/sling-scheduled-jobs-vs-sling-scheduler/
I believe in AEMaaCS you will need to use Sling Scheduled Jobs (org.apache.sling.event.jobs.*), because they do persist their state. And you will need that as due to the fact that on cloud the pods can go up and down.

Looking further on the specs page https://sling.apache.org/documentation/bundles/apache-sling-eventing-and-job-handling.html you will find the ways to actually implement it. One hint here from me is that you will need to use the method ScheduleBuilder.cron() to schedule repetitive tasks. It accepts a cron expression as argument: https://sling.apache.org/apidocs/sling7/org/apache/sling/event/jobs/JobBuilder.ScheduleBuilder.html#cron-java.lang.String-

You can use a utility tool to generate the desired cron expression that you need: http://www.cronmaker.com

Another similar topic: https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/schedule-sling-jobs/m-p/597117

3 replies

Tethich
Community Advisor
TethichCommunity AdvisorAccepted solution
Community Advisor
December 16, 2024

Hi @newbie34 
Let me start by asking you, where is your bottleneck ? Is it because you need to make it work in AEMaaCS ?

 

Assuming it is, I will advise you to start with this article: https://cqdump.joerghoh.de/2022/06/20/sling-scheduled-jobs-vs-sling-scheduler/
I believe in AEMaaCS you will need to use Sling Scheduled Jobs (org.apache.sling.event.jobs.*), because they do persist their state. And you will need that as due to the fact that on cloud the pods can go up and down.

Looking further on the specs page https://sling.apache.org/documentation/bundles/apache-sling-eventing-and-job-handling.html you will find the ways to actually implement it. One hint here from me is that you will need to use the method ScheduleBuilder.cron() to schedule repetitive tasks. It accepts a cron expression as argument: https://sling.apache.org/apidocs/sling7/org/apache/sling/event/jobs/JobBuilder.ScheduleBuilder.html#cron-java.lang.String-

You can use a utility tool to generate the desired cron expression that you need: http://www.cronmaker.com

Another similar topic: https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/schedule-sling-jobs/m-p/597117

newbie34Author
Level 2
December 19, 2024

Hi @tethich  , 

Thank you for your reply and for the resources . I am able to implement scheduler using commons scheduler and as a sling job using cron . 

I got to learn  about Job consumer and producer . Thanks again .

arunpatidar
Community Advisor
Community Advisor
December 17, 2024

Hi @newbie34 

You can use sling scheduler/job in conjunction with sling feature flag -

https://sling.apache.org/documentation/the-sling-engine/featureflags.html 

Arun Patidar