Expand my Community achievements bar.

SOLVED

Sheduled job does not work anymore (Scheduling service [java.lang.Runnable] failed)

Avatar

Level 7

The logfile error.log shows me following error:

18.10.2022 14:20:44.980 *INFO* [CM Event Dispatcher (Fire ConfigurationEvent: pid=xx.xxx.MyCronJob)] xx.xxx.my-bundle Service [xx.xxx.MyCronJob,9912, [java.lang.Runnable]] ServiceEvent UNREGISTERING
18.10.2022 14:20:44.985 *ERROR* [CM Event Dispatcher (Fire ConfigurationEvent: pid=xx.xxx.MyCronJob)] org.apache.sling.commons.scheduler.impl.WhiteboardHandler Scheduling service [java.lang.Runnable] failed.
18.10.2022 14:20:44.985 *INFO* [CM Event Dispatcher (Fire ConfigurationEvent: pid=xx.xxx.MyCronJob)] xx.xxx.my-bundle Service [xx.xxx.MyCronJob,9913, [java.lang.Runnable]] ServiceEvent REGISTERED

 

The configuration class looks so:

public @interface MyCronJobConfig {
    @AttributeDefinition(name = "Cron Pattern", description = "...")
    String scheduler_expression() default "0 30 2 * * *";

    @AttributeDefinition(name = "Concurrent Jobs", description = "...", type = AttributeType.BOOLEAN)
    boolean scheduler_concurrent() default true;

    @AttributeDefinition(name = "Enabled", description = "...", type = AttributeType.BOOLEAN)
    boolean enabled() default true;
}

 

And the business logic:

@component(service = Runnable.class, immediate = true, configurationPolicy = ConfigurationPolicy.REQUIRE)
@Designate(ocd = MyCronJobConfig.class)
@Slf4j
public class MyCronJob implements Runnable {
   private BundleContext bundleContext;

    protected void activate(ComponentContext componentContext) throws Exception {
        this.bundleContext = componentContext.getBundleContext();
        log.info("cron job activated.");
    }

    public void run() {
        log.info("cron job started.");
        log.info("cron job finished.");
    }
}

The problem is, the run() method won't be executed. I can see it while no log output does appear in log file. Where is my mistake?

 

Thanks for your help.

1 Accepted Solution

Avatar

Correct answer by
Community Advisor
9 Replies

Avatar

Level 4

Hi @Magicr , Please follow the tutorial in the motioned link https://aem.redquark.org/2018/10/day-13-schedulers-in-aem.html

I think lot needs to be added in the business logic to make the scheduler.

 

Avatar

Community Advisor

you need to add osgi config because of 

configurationPolicy = ConfigurationPolicy.REQUIRE


Arun Patidar

Avatar

Level 7

Where do I have to  place this line? If you look at my posted code snippets I have alerady added it.

Avatar

Correct answer by
Community Advisor

Please check sample code here, try with this sample code?

https://github.com/arunpatidar02/aemaacs-aemlab/blob/master/core/src/main/java/com/community/aemlab/... 



Arun Patidar

Avatar

Level 5

@Magicr -

Refer

https://blog.developer.adobe.com/aem-6-4-creating-a-scheduler-using-osgi-r6-annotations-4ad0b8c6fce7

Also @arunpatidar  is correct as per your code make sure you not missing configurations. 

configurationPolicy = ConfigurationPolicy.REQUIRE

 

Thanks

Avatar

Level 7

Have you also read my code snippets? The annotations do exists, the line for confugurationPolicy exists either. Also, the activation method will be executed and the configuration does appear in webconsole from AEM.

Avatar

Level 1

Hi Are you able to solve this. We are facing the same issue. Can you post the solution here.

Avatar

Level 7

I couldn't solve the problem. I restartet from scratch days later and the described sitution has gone.