Hi All,
I have a scheduler, which scans assets and looks for expiring and send email notifications.
Here problem is instead of 1 email i am receiving 4 email for same content.
I had deployed code with with different cron expression in config file, seems all of them storing as a different PID. How do we make sure only one PID runs. here is my schedule job
Class is made Runnable with immediate true
have OCD properties and below schedule options
@Activate
protected void activate(Config cfg) {
this.config = cfg;
removeJob();
scheduleJob(cfg);
}
@Modified
protected void modified(Config cfg) {
removeJob();
this.config = cfg;
scheduleJob(cfg);
}
@Deactivate
protected void deactivate() {
removeJob();
}
private void scheduleJob(Config cfg) {
if (!cfg.enabled()) {
LOG.info("AssetExpiryScheduler disabled by config.");
return;
}
this.jobId = cfg.schedulerName();
ScheduleOptions opts = scheduler.EXPR(cfg.scheduler_expression());
opts.name(jobId);
opts.canRunConcurrently(false);
scheduler.schedule(this, opts);
LOG.info("Scheduled job '{}' with expression '{}'", cfg.schedulerName(), cfg.scheduler_expression());
this.config = cfg;
}
private void removeJob() {
if (jobId != null) {
scheduler.unschedule(jobId);
jobId = null;
}
}