Enable / Disable scheduler via Context Aware Configuration

Avatar

Avatar
Level 1
ashishj32959934
Level 1

Likes

0 likes

Total Posts

3 posts

Correct reply

0 solutions
View profile

Avatar
Level 1
ashishj32959934
Level 1

Likes

0 likes

Total Posts

3 posts

Correct reply

0 solutions
View profile
ashishj32959934
Level 1

23-03-2021

Hi All,

 

I created a scheduler which is having enable / disable configuration at OSGI level. I want to move this enable / disable checkbox to Context Aware Configuration so that it can be possible to enable it for different tenants. 

 

Is it possible to do that ?

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Springboard
Level 7
KiranVedantam1992
Level 7

Likes

198 likes

Total Posts

214 posts

Correct reply

61 solutions
Top badges earned
Springboard
Give Back 5
Ignite 1
Affirm 50
Validate 1
View profile

Avatar
Springboard
Level 7
KiranVedantam1992
Level 7

Likes

198 likes

Total Posts

214 posts

Correct reply

61 solutions
Top badges earned
Springboard
Give Back 5
Ignite 1
Affirm 50
Validate 1
View profile
KiranVedantam1992
Level 7

23-03-2021

Hi @ashishj32959934,

 

yes, this is possible. Create a context-aware configuration and access it in the scheduler like this:

 

Resource contentResource = resourceResolver.getResource("/content/mysite/page1");

Resource configResource = configurationResourceResolver.getResource(contentResource, "my-bucket", "my-config");

 

More info here: https://sling.apache.org/documentation/bundles/context-aware-configuration/context-aware-configurati...

 

Hope this helps.

 

Thanks,

Kiran Vedantam.

Answers (2)

Answers (2)

Avatar

Avatar
Applaud 25
Level 10
asutosh_jena
Level 10

Likes

594 likes

Total Posts

705 posts

Correct reply

208 solutions
Top badges earned
Applaud 25
Give Back 100
Boost 500
Affirm 100
Ignite 1
View profile

Avatar
Applaud 25
Level 10
asutosh_jena
Level 10

Likes

594 likes

Total Posts

705 posts

Correct reply

208 solutions
Top badges earned
Applaud 25
Give Back 100
Boost 500
Affirm 100
Ignite 1
View profile
asutosh_jena
Level 10

23-03-2021

Hi @ashishj32959934 

Context aware config works based on the context (page/domain) path and OSGi config works based on repo/web console/run mode value. Scheduler which is running as a independent module will not have access to the context and it does not depend on any request or it does not know from which context the request is coming. It runs independently based on a schedule. So you will not be able to use the CAC here to manage the flag.
https://sling.apache.org/documentation/bundles/context-aware-configuration/context-aware-configurati...

 

Thanks!

Avatar

Avatar
Ignite 1
MVP
Ankur_Khare
MVP

Likes

160 likes

Total Posts

370 posts

Correct reply

58 solutions
Top badges earned
Ignite 1
Validate 10
Validate 1
Give Back 50
Give Back 5
View profile

Avatar
Ignite 1
MVP
Ankur_Khare
MVP

Likes

160 likes

Total Posts

370 posts

Correct reply

58 solutions
Top badges earned
Ignite 1
Validate 10
Validate 1
Give Back 50
Give Back 5
View profile
Ankur_Khare
MVP

23-03-2021

I think you cant move the config to context aware config rather you can use the context config in scheduler so that based on that config value your scheduler will get executed.

ashishj32959934

Hi Ankur,

 

But how the scheduler will be updated after updating the value in CA Config ?

After updating the OSGI config it will trigger the code of scheduler and make it enable / disable, how we will achieve this trigger from CA Config ?

Jörg_Hoh

The scheduler is a singleton within AEM, and it does not know anything about. the content or the tenants you have. Also this topic is a bit special, because it's about triggering a job (and not about reading data which configures the runtime behavior of that job).

 

So to give authors the chance to configure the time when a job is triggered, you probably have to keep track of all configured times within CAC. So you need a service, which picks up the configured scheduling expressions and configures the scheduler accordingly. 

Another approach would be to start the scheduled job every minute or so and check if a tenant is configured to run at this time. And then starts the configured processing.

 

Caution: In any way, I would definitely apply some constraints here, because you want and need some control over that, and for example you don't want to run a intensive job while the backup is running or during deployment.