Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.
SOLVED

Enable / Disable scheduler via Context Aware Configuration

Avatar

Level 1

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 ?

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

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.

View solution in original post

5 Replies

Avatar

Community Advisor

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

Correct answer by
Community Advisor

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.

Avatar

Community Advisor

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.

Avatar

Level 1

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 ?

Avatar

Employee Advisor

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.