I have created a custom action, which can be invoked as a rule, or from a query cronjob.The spring bean that registers the cronjob + query is a java class that extends CronScheduledQueryBasedTemplateActionDefinition
. I have overridden its queryTemplate
setters and getters to be able to load my query from the java code, and added a isEnabled
boolean flag. This is switched to true or false from config.Now, I want to make sure that on startup, the cron is not scheduled at all if isEnabled
is false. To that end, I wrote the following method:
@Override
public void afterPropertiesSet() throws Exception {
if(isEnabled) {
logger.warn("Scheduling "+NAME);
super.afterPropertiesSet();
} else {
logger.warn("Didn't schedule "+NAME+" because it was disabled.");
}
}
The superclass's afterPropertiesSet method registers the cron with the scheduler.Unfortunately, this doesn't work. Corresponding log warnings never even show, suggesting that the method is never invoked. However, the following code works flawlessly:
@Override
public List<NodeRef> getNodes() {
if(isEnabled) {
logger.warn("getNodes: "+NAME);
return super.getNodes();
} else {
logger.warn("Didn't get nodes for "+NAME+" because it was disabled.");
return new ArrayList<NodeRef>();
}
}
Of course, the cron is still scheduled, so the getNodes method is still invoked at scheduled times. However, it always returns an empty response, so no furthur actions are taken.I want to be able to make sure the cronjob is never scheduled. Why does my first attempt not work, and what should I try instead?