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"));
});
}
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;
}
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;
}
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);
}
}
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;
}
Aggregations