Search in sources :

Example 6 with SchedulerFactoryBean

use of org.springframework.scheduling.quartz.SchedulerFactoryBean in project spring-boot by spring-projects.

the class QuartzAutoConfigurationTests method transactionManagerWithQuartzTransactionManagerUsedWhenMultiplePresent.

@Test
void transactionManagerWithQuartzTransactionManagerUsedWhenMultiplePresent() {
    this.contextRunner.withUserConfiguration(QuartzJobsConfiguration.class, MultipleTransactionManagersConfiguration.class).withPropertyValues("spring.quartz.job-store-type=jdbc").run((context) -> {
        SchedulerFactoryBean schedulerFactoryBean = context.getBean(SchedulerFactoryBean.class);
        assertThat(schedulerFactoryBean).extracting("transactionManager").isEqualTo(context.getBean("quartzTransactionManager"));
    });
}
Also used : SchedulerFactoryBean(org.springframework.scheduling.quartz.SchedulerFactoryBean) Test(org.junit.jupiter.api.Test)

Example 7 with SchedulerFactoryBean

use of org.springframework.scheduling.quartz.SchedulerFactoryBean in project new-cloud by xie-summer.

the class QuartzConfigration method schedulerFactoryBean.

@Bean
public SchedulerFactoryBean schedulerFactoryBean() {
    SchedulerFactoryBean schedulerFactoryBean = new SchedulerFactoryBean();
    try {
        schedulerFactoryBean.setQuartzProperties(quartzProperties());
        schedulerFactoryBean.setJobFactory(myJobFactory);
        // 用于quartz集群,QuartzScheduler 启动时更新己存在的Job
        schedulerFactoryBean.setOverwriteExistingJobs(true);
        // 延时启动,应用启动1秒后
        schedulerFactoryBean.setStartupDelay(1);
    } catch (Exception e) {
    }
    return schedulerFactoryBean;
}
Also used : SchedulerFactoryBean(org.springframework.scheduling.quartz.SchedulerFactoryBean) IOException(java.io.IOException) PropertiesFactoryBean(org.springframework.beans.factory.config.PropertiesFactoryBean) Bean(org.springframework.context.annotation.Bean) SchedulerFactoryBean(org.springframework.scheduling.quartz.SchedulerFactoryBean)

Example 8 with SchedulerFactoryBean

use of org.springframework.scheduling.quartz.SchedulerFactoryBean 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)

Example 9 with SchedulerFactoryBean

use of org.springframework.scheduling.quartz.SchedulerFactoryBean in project CzechIdMng by bcvsolutions.

the class SchedulerConfig method schedulerFactoryBean.

/**
 * Enables scheduler injection through application
 *
 * @param dataSource
 * @param jobFactory
 * @return
 * @throws IOException
 */
@Bean
public SchedulerFactoryBean schedulerFactoryBean(ApplicationContext context) {
    try {
        Properties quartzProperties = quartzProperties();
        SchedulerFactoryBean factory = new SchedulerFactoryBean();
        // update triggers in DB when config file is changed
        factory.setOverwriteExistingJobs(true);
        // if store is set to DB set data source, else store in RAM
        Object store = quartzProperties.get("org.quartz.jobStore.class");
        if (store != null && !StringUtils.equals(store.toString(), RAMJobStore.class.getCanonicalName())) {
            DataSource dataSource = (DataSource) context.getBean("dataSource");
            factory.setDataSource(dataSource);
        }
        factory.setJobFactory(jobFactory(context));
        factory.setQuartzProperties(quartzProperties);
        return factory;
    } catch (IOException ex) {
        throw new CoreException("Quartz properties initialization failed", ex);
    }
}
Also used : CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) SchedulerFactoryBean(org.springframework.scheduling.quartz.SchedulerFactoryBean) RAMJobStore(org.quartz.simpl.RAMJobStore) IOException(java.io.IOException) Properties(java.util.Properties) DataSource(javax.sql.DataSource) PropertiesFactoryBean(org.springframework.beans.factory.config.PropertiesFactoryBean) SchedulerFactoryBean(org.springframework.scheduling.quartz.SchedulerFactoryBean) Bean(org.springframework.context.annotation.Bean)

Example 10 with SchedulerFactoryBean

use of org.springframework.scheduling.quartz.SchedulerFactoryBean in project kylo by Teradata.

the class QuartzSpringConfiguration method schedulerFactoryBean.

@Bean(name = "schedulerFactoryBean")
public SchedulerFactoryBean schedulerFactoryBean(@Qualifier("dataSource") DataSource dataSource) {
    SchedulerFactoryBean scheduler = new SchedulerFactoryBean();
    scheduler.setApplicationContextSchedulerContextKey("applicationContext");
    Resource resource = new ClassPathResource("quartz.properties");
    if (resource.exists()) {
        scheduler.setConfigLocation(resource);
        scheduler.setDataSource(dataSource);
    }
    // Enable autowiring of Beans inside each QuartzJobBean
    AutowiringSpringBeanJobFactory jobFactory = new AutowiringSpringBeanJobFactory();
    jobFactory.setApplicationContext(applicationContext);
    scheduler.setJobFactory(jobFactory);
    return scheduler;
}
Also used : ClassPathResource(org.springframework.core.io.ClassPathResource) Resource(org.springframework.core.io.Resource) SchedulerFactoryBean(org.springframework.scheduling.quartz.SchedulerFactoryBean) ClassPathResource(org.springframework.core.io.ClassPathResource) Bean(org.springframework.context.annotation.Bean) SchedulerFactoryBean(org.springframework.scheduling.quartz.SchedulerFactoryBean)

Aggregations

SchedulerFactoryBean (org.springframework.scheduling.quartz.SchedulerFactoryBean)28 Bean (org.springframework.context.annotation.Bean)20 PropertiesFactoryBean (org.springframework.beans.factory.config.PropertiesFactoryBean)7 ClassPathResource (org.springframework.core.io.ClassPathResource)6 IOException (java.io.IOException)5 Properties (java.util.Properties)5 Test (org.junit.jupiter.api.Test)3 JobDetail (org.quartz.JobDetail)3 Trigger (org.quartz.Trigger)3 CoreException (eu.bcvsolutions.idm.core.api.exception.CoreException)2 Map (java.util.Map)2 PostConstruct (javax.annotation.PostConstruct)2 SchedulerException (org.quartz.SchedulerException)2 ServerSettings (com.radensolutions.reporting.service.ServerSettings)1 Job (com.weicoder.frame.quartz.Job)1 SchedulerManager (eu.bcvsolutions.idm.core.scheduler.api.service.SchedulerManager)1 DefaultSchedulerManager (eu.bcvsolutions.idm.core.scheduler.service.impl.DefaultSchedulerManager)1 ParseException (java.text.ParseException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1