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.
Solved! Go to Solution.
Views
Replies
Total Likes
Please check sample code here, try with this sample code?
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.
you need to add osgi config because of
configurationPolicy = ConfigurationPolicy.REQUIRE
Where do I have to place this line? If you look at my posted code snippets I have alerady added it.
Please check sample code here, try with this sample code?
@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
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.
Hi Are you able to solve this. We are facing the same issue. Can you post the solution here.
I couldn't solve the problem. I restartet from scratch days later and the described sitution has gone.
Views
Likes
Replies
Views
Likes
Replies