Enable / Disable scheduler via Context Aware Configuration | Community
Skip to main content
ashishj32959934
March 23, 2021
Solved

Enable / Disable scheduler via Context Aware Configuration

  • March 23, 2021
  • 3 replies
  • 1911 views

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 ?

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 Kiran_Vedantam

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-configuration.html

 

Hope this helps.

 

Thanks,

Kiran Vedantam.

3 replies

Asutosh_Jena_
Community Advisor
Community Advisor
March 23, 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-configuration.html

 

Thanks!

Kiran_Vedantam
Community Advisor
Kiran_VedantamCommunity AdvisorAccepted solution
Community Advisor
March 23, 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-configuration.html

 

Hope this helps.

 

Thanks,

Kiran Vedantam.

Ankur_Khare
Community Advisor
Community Advisor
March 23, 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
March 23, 2021

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 ?