Scheduled jobs not executed in AEMaaCS
Hello community,
for our new project we need scheduled jobs for running e.g. importer tasks during the night. I am using sling jobs for many years now - but the scheduled jobs in AEMaaCS make me crazy - they sometimes run, sometimes not. I believe this is due to the architecture of AEMaaCS using an author cluster and depending on which instance the job was created and which is active it gets triggered or not. My question, how can I schedule sling jobs by using a cron expression which will guaranteed run?
Which is the golden approach to be used in AEMaaCS?
Code snippets:
Job executor:
(service = JobExecutor.class, property = {
JobConsumer.PROPERTY_TOPICS + "=" + PimImportRunnerJob.PIM_IMPORT_JOB_TOPIC})
public class PimImportRunnerJob implements JobExecutor {
public JobExecutionResult process (final Job job, JobExecutionContext context) {
...
}
}
the job gets scheduled in the activate method of my osgi service
(service = PimImporterV2RuntimeService.class, immediate = true)
@Designate(ocd = PimImporterV2RuntimeServiceConfiguration.class)
public class PimImporterV2RuntimeServiceImpl implements PimImporterV2RuntimeService {
...
@Activate
@Modified
public void activate(final PimImporterV2RuntimeServiceConfiguration config) {
JobBuilder builder = jobManager.createJob(PimImportRunnerJob.PIM_IMPORT_JOB_TOPIC);
JobBuilder.ScheduleBuilder scheduleBuilder = builder.schedule();
final String expr = ...
scheduleBuilder.cron(expr);
ScheduledJobInfo scheduledJobInfo = scheduleBuilder.add();
if (scheduledJobInfo == null) {
LOG.info("Error adding job '{}' to scheduler", PimImportRunnerJob.PIM_IMPORT_JOB_TOPIC);
} else {
LOG.info("Scheduler successfully added job '{}'", PimImportRunnerJob.PIM_IMPORT_JOB_TOPIC);
}
}
When deployed to AEMaaCS the log says: "Scheduler successfully added..."
For testing i set my cron to execute the job every 15 min. The logs showed me, that the job ran 12 hours ago for the last time...
Locally, by using AEM SDK, everything's fine.
Any ideas?
Thanks and best regards,
Martin