Search in sources :

Example 1 with DefaultSchedulerManager

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;
}
Also used : DefaultSchedulerManager(eu.bcvsolutions.idm.core.scheduler.service.impl.DefaultSchedulerManager) Scheduler(org.quartz.Scheduler) DefaultSchedulerManager(eu.bcvsolutions.idm.core.scheduler.service.impl.DefaultSchedulerManager) SchedulerManager(eu.bcvsolutions.idm.core.scheduler.api.service.SchedulerManager) JobKey(org.quartz.JobKey) JobDetail(org.quartz.JobDetail) CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) BeansException(org.springframework.beans.BeansException) DependsOn(org.springframework.context.annotation.DependsOn) PropertiesFactoryBean(org.springframework.beans.factory.config.PropertiesFactoryBean) SchedulerFactoryBean(org.springframework.scheduling.quartz.SchedulerFactoryBean) Bean(org.springframework.context.annotation.Bean)

Aggregations

CoreException (eu.bcvsolutions.idm.core.api.exception.CoreException)1 SchedulerManager (eu.bcvsolutions.idm.core.scheduler.api.service.SchedulerManager)1 DefaultSchedulerManager (eu.bcvsolutions.idm.core.scheduler.service.impl.DefaultSchedulerManager)1 JobDetail (org.quartz.JobDetail)1 JobKey (org.quartz.JobKey)1 Scheduler (org.quartz.Scheduler)1 BeansException (org.springframework.beans.BeansException)1 PropertiesFactoryBean (org.springframework.beans.factory.config.PropertiesFactoryBean)1 Bean (org.springframework.context.annotation.Bean)1 DependsOn (org.springframework.context.annotation.DependsOn)1 SchedulerFactoryBean (org.springframework.scheduling.quartz.SchedulerFactoryBean)1