I configured a scheduler in AEM6.5 like below.
In my opinion I should be getting an entry in the error.log every 2min but I am not.
I can see the SimpleScheduleTask in /system/console/configMgr
/**
* A simple demo for cron-job like tasks that get executed regularly. It also
* demonstrates how property values can be set. Users can set the property
* values in /system/console/configMgr
*/
@Designate(ocd = SimpleScheduledTask.Config.class)
@Component(immediate = true,
service = {SimpleScheduledTask.class, Runnable.class},
configurationPolicy = ConfigurationPolicy.REQUIRE)
public class SimpleScheduledTask implements Runnable {
private static final Logger LOGGER = LoggerFactory.getLogger(SimpleScheduledTask.class);
@Reference
private TagVerificationService tagVerificationService;
@ObjectClassDefinition(name = "Annotation Demo Scheduled Task - OSGi", description = "Simple demo for cron-job like task with properties")
public @interface Config {
@SuppressWarnings("squid:S00100") // Suppress naming convention warning because underscores are mapped to periods
@AttributeDefinition(name = "Expression", description = "Quartz scheduler expression to define when tokens are cleaned up")
String scheduler_expression() default "0 0/2 * * * ?";
@AttributeDefinition(name = "warnMail", description = "Address, to send the warning mail.")
String[] warnMail();
}
private SimpleScheduledTask.Config config;
@Override
public void run() {
LOGGER.trace("SimpleScheduledTask is now running");
//TODO for each article verify its tags exist
tagVerificationService.verifyTagsExist();
}
@Activate
private void activate(final Config config) {
this.config = config;
}
}
Solved! Go to Solution.
Views
Replies
Total Likes
I don't think that this is the case.
When you were using SCR annotations, it did not matter if you annotated the @component annotation with additional properties or if you were providing them inline (and configurable). But technically this was not correct, as there is a disctinction between those properties.
Now with the OSGI r6 annotations (@Designate, @ObjectClassDefinition and others) this has been rectified, and that sloppy (but indeed sometime useful) behaviour is no longer possible.
(You can see the differences in the generated XML in target/classes/OSGI-INF)
I see the log statement is set at "trace" level. Have you enabled/set the logger for error.log at "trace" level? Normally, the error.log is set at the "INFO" level. Please check that or create a new log file using Log Support in OSGI menu for only this class and set the log level of the log file to "trace" level.
Hi @anasustic
Are you able to see you scheduler scheduled under the http://localhost:4502/system/console/status-slingscheduler . If its displayed with the next fire time then it will fire at the specified time. If not then either it can be due to some dependency issue or any config issue.
Please check the below implementation following the white board pattern , I can see couple of changes with the same , worth giving a comparison and see if this works and can add additional logic on top
I don't think that this is the case.
When you were using SCR annotations, it did not matter if you annotated the @component annotation with additional properties or if you were providing them inline (and configurable). But technically this was not correct, as there is a disctinction between those properties.
Now with the OSGI r6 annotations (@Designate, @ObjectClassDefinition and others) this has been rectified, and that sloppy (but indeed sometime useful) behaviour is no longer possible.
(You can see the differences in the generated XML in target/classes/OSGI-INF)
Thanks so much for your reply.
I reverted my scheduled task to the solution https://github.com/adobe/aec-bot-integrations/blob/master/aem-chatbot-demo/core/src/main/java/com/ad... and now I can see my scheduled task listed under http://localhost:4502/system/console/status-slingscheduler as @Sudheer_Sundalam and @sherinregi suggested and the log entry is also visible in the logs.
@Designate(ocd = TagVerificationScheduledTask.Config.class)
@Component(service = {Runnable.class})
public class TagVerificationScheduledTask implements Runnable {
private static final Logger LOGGER = LoggerFactory.getLogger(TagVerificationScheduledTask.class);
@ObjectClassDefinition(name="A scheduled task that verifies tags in blog articles",
description = "A scheduled task that verifies tags in blog articles")
public static @interface Config {
@AttributeDefinition(name = "Cron-job expression. Default: run every two minutes.")
String scheduler_expression() default "0 0/2 * * * ?";
@AttributeDefinition(name = "Enabled", description = "Enable Scheduler")
boolean serviceEnabled() default true;
@AttributeDefinition(name = "Concurrent task",
description = "Whether or not to schedule this task concurrently")
boolean scheduler_concurrent() default false;
@AttributeDefinition(name = "warnMail", description = "Email address for sending a warning message.")
String[] warnMail() default "";
}
private final Logger logger = LoggerFactory.getLogger(getClass());
private String[] warnMail;
@Override
public void run() {
logger.debug("TagVerificationScheduler is now running, warnMail='{}'", warnMail);
}
@Activate
protected void activate(final Config config) {
warnMail = config.warnMail();
}
}
I also checked the /target/classes/OSGI-INF XML as @joerghoh suggested and it looks like this when working correctly.
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.3.0" name="xxx.component.structure.blog.TagVerificationScheduledTask" activate="activate">
<property name="scheduler.expression" type="String" value="*/30 * * * * ?"/>
<property name="scheduler.concurrent" type="Boolean" value="false"/>
<property name="myParameter" type="String" value=""/>
<service>
<provide interface="java.lang.Runnable"/>
</service>
<implementation class=xxx.component.structure.blog.TagVerificationScheduledTask"/>
</scr:component>
I still have a question @joerghoh and that is how do I know when to use SCR Annotations and OSGi R6 Annotations?
Hi,
You need to create a osgi config file because of policy, otherwise service will not be active
Don't rely on the default config in SimpleScheduleTask in /system/console/configMgr, until it is checked
configurationPolicy = ConfigurationPolicy.REQUIRE
Example of default(unchecked) and osgi config file(checked)
Views
Likes
Replies
Views
Likes
Replies
Views
Likes
Replies