use of eu.bcvsolutions.idm.core.scheduler.service.impl.DefaultSchedulerManager in project CzechIdMng by bcvsolutions.
the class SchedulerConfig method schedulerManager.
@DependsOn(CoreFlywayConfig.NAME)
@Bean(name = "schedulerManager")
public SchedulerManager schedulerManager(ApplicationContext context, IdmDependentTaskTriggerRepository dependentTaskTriggerRepository) {
Scheduler scheduler = schedulerFactoryBean(context).getScheduler();
SchedulerManager manager = new DefaultSchedulerManager(context, schedulerFactoryBean(context).getScheduler(), dependentTaskTriggerRepository);
// read all task - checks obsolete task types and remove them before scheduler starts automatically
try {
for (JobKey jobKey : scheduler.getJobKeys(GroupMatcher.jobGroupEquals(DefaultSchedulerManager.DEFAULT_GROUP_NAME))) {
try {
JobDetail jobDetail = scheduler.getJobDetail(jobKey);
if (jobDetail == null) {
// job does not exists
return null;
}
// test task is still installed
jobDetail.getJobClass().getDeclaredConstructor().newInstance();
} catch (org.quartz.SchedulerException ex) {
if (ex.getCause() instanceof ClassNotFoundException) {
manager.deleteTask(jobKey.getName());
//
LOG.warn("Job [{}] inicialization failed, job class was removed, scheduled task is removed.", jobKey, ex);
} else {
throw new CoreException(ex);
}
} catch (ReflectiveOperationException | BeansException | IllegalArgumentException ex) {
manager.deleteTask(jobKey.getName());
//
LOG.warn("Job [{}] inicialization failed, scheduled task is removed", jobKey, ex);
}
}
} catch (org.quartz.SchedulerException ex) {
throw new CoreException(ex);
}
//
return manager;
}
Aggregations