Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn More

View all

Sign in to view all badges

Restricting Scheduler to run in published Env.

Avatar

Avatar
Validate 1
Level 1
venusj64090183
Level 1

Like

1 like

Total Posts

1 post

Correct Reply

0 solutions
Top badges earned
Validate 1
Boost 1
View profile

Avatar
Validate 1
Level 1
venusj64090183
Level 1

Like

1 like

Total Posts

1 post

Correct Reply

0 solutions
Top badges earned
Validate 1
Boost 1
View profile
venusj64090183
Level 1

11-10-2019

I want to restrict the scheduler to run in published env. which approach will be good for this?

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Ignite 1
Level 3
khamat_bn
Level 3

Likes

31 likes

Total Posts

54 posts

Correct Reply

12 solutions
Top badges earned
Ignite 1
Give Back 3
Give Back
Boost 5
Boost 3
View profile

Avatar
Ignite 1
Level 3
khamat_bn
Level 3

Likes

31 likes

Total Posts

54 posts

Correct Reply

12 solutions
Top badges earned
Ignite 1
Give Back 3
Give Back
Boost 5
Boost 3
View profile
khamat_bn
Level 3

12-10-2019

In the run() of scheduler you have to runmode wheather its autour or publisher

@Reference

    private SlingSettingsService settingsService;

    private Set<String> runModes;

    @Override

    public void run() {

        this.runModes = settingsService.getRunModes();

        if (null != runModes && runModes.contains("author")) {

//your code goes here...

}

Answers (3)

Answers (3)

Avatar

Avatar
Coach
Employee
Jörg_Hoh
Employee

Likes

1,118 likes

Total Posts

3,149 posts

Correct Reply

1,073 solutions
Top badges earned
Coach
Give back 600
Ignite 5
Ignite 3
Ignite 1
View profile

Avatar
Coach
Employee
Jörg_Hoh
Employee

Likes

1,118 likes

Total Posts

3,149 posts

Correct Reply

1,073 solutions
Top badges earned
Coach
Give back 600
Ignite 5
Ignite 3
Ignite 1
View profile
Jörg_Hoh
Employee

13-10-2019

While the answer by khamat.bn​ works for that, the best solution for this is the one by arpitv27529355​: You should never hardcode this in the code, but rely on configuration instead.

Personally I would consider every call of SlingSettingsService.getRunmodes() as bad practice.

Avatar

Avatar
Validate 1
MVP
ArpitVarshney
MVP

Likes

136 likes

Total Posts

185 posts

Correct Reply

36 solutions
Top badges earned
Validate 1
Establish
Give Back 5
Give Back 3
Give Back 25
View profile

Avatar
Validate 1
MVP
ArpitVarshney
MVP

Likes

136 likes

Total Posts

185 posts

Correct Reply

36 solutions
Top badges earned
Validate 1
Establish
Give Back 5
Give Back 3
Give Back 25
View profile
ArpitVarshney
MVP

12-10-2019

Hi venusj64090183

In your service, you can define policy = ConfigurationPolicy.REQUIRE as below

@Component(policy = ConfigurationPolicy.REQUIRE) 

Now create OSGi config only for publish run mode. Your service will not satisfied with the author instance.

Reference: OSGi component in AEM that is active only in specific run mode (say, publish). – Compute Patterns

Regards,

Arpit

Avatar

Avatar
Ignite 1
MVP
Ankur_Khare
MVP

Likes

159 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

159 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

11-10-2019

Use run mode configuration.

Add a config in config.author folder so that scheduler will not run in author

Add a config in config.publish folder so that it gets executed in publish.

Hope this helps.