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(200);
} catch (Exception e) {
}
return schedulerFactoryBean;
}
use of org.springframework.scheduling.quartz.SchedulerFactoryBean in project spring-boot by spring-projects.
the class QuartzAutoConfiguration method quartzScheduler.
@Bean
@ConditionalOnMissingBean
public SchedulerFactoryBean quartzScheduler(QuartzProperties properties, ObjectProvider<SchedulerFactoryBeanCustomizer> customizers, ObjectProvider<JobDetail> jobDetails, Map<String, Calendar> calendars, ObjectProvider<Trigger> triggers, ApplicationContext applicationContext) {
SchedulerFactoryBean schedulerFactoryBean = new SchedulerFactoryBean();
SpringBeanJobFactory jobFactory = new SpringBeanJobFactory();
jobFactory.setApplicationContext(applicationContext);
schedulerFactoryBean.setJobFactory(jobFactory);
if (properties.getSchedulerName() != null) {
schedulerFactoryBean.setSchedulerName(properties.getSchedulerName());
}
schedulerFactoryBean.setAutoStartup(properties.isAutoStartup());
schedulerFactoryBean.setStartupDelay((int) properties.getStartupDelay().getSeconds());
schedulerFactoryBean.setWaitForJobsToCompleteOnShutdown(properties.isWaitForJobsToCompleteOnShutdown());
schedulerFactoryBean.setOverwriteExistingJobs(properties.isOverwriteExistingJobs());
if (!properties.getProperties().isEmpty()) {
schedulerFactoryBean.setQuartzProperties(asProperties(properties.getProperties()));
}
schedulerFactoryBean.setJobDetails(jobDetails.orderedStream().toArray(JobDetail[]::new));
schedulerFactoryBean.setCalendars(calendars);
schedulerFactoryBean.setTriggers(triggers.orderedStream().toArray(Trigger[]::new));
customizers.orderedStream().forEach((customizer) -> customizer.customize(schedulerFactoryBean));
return schedulerFactoryBean;
}
use of org.springframework.scheduling.quartz.SchedulerFactoryBean in project spring-boot by spring-projects.
the class QuartzAutoConfigurationTests method validateDefaultProperties.
@Test
void validateDefaultProperties() {
this.contextRunner.withUserConfiguration(ManualSchedulerConfiguration.class).run((context) -> {
assertThat(context).hasSingleBean(SchedulerFactoryBean.class);
SchedulerFactoryBean schedulerFactory = context.getBean(SchedulerFactoryBean.class);
QuartzProperties properties = new QuartzProperties();
assertThat(properties.isAutoStartup()).isEqualTo(schedulerFactory.isAutoStartup());
assertThat(schedulerFactory).hasFieldOrPropertyWithValue("startupDelay", (int) properties.getStartupDelay().getSeconds());
assertThat(schedulerFactory).hasFieldOrPropertyWithValue("waitForJobsToCompleteOnShutdown", properties.isWaitForJobsToCompleteOnShutdown());
assertThat(schedulerFactory).hasFieldOrPropertyWithValue("overwriteExistingJobs", properties.isOverwriteExistingJobs());
});
}
use of org.springframework.scheduling.quartz.SchedulerFactoryBean in project spring-boot by spring-projects.
the class QuartzAutoConfigurationTests method withCustomConfiguration.
@Test
void withCustomConfiguration() {
this.contextRunner.withPropertyValues("spring.quartz.auto-startup=false", "spring.quartz.startup-delay=1m", "spring.quartz.wait-for-jobs-to-complete-on-shutdown=true", "spring.quartz.overwrite-existing-jobs=true").run((context) -> {
assertThat(context).hasSingleBean(SchedulerFactoryBean.class);
SchedulerFactoryBean schedulerFactory = context.getBean(SchedulerFactoryBean.class);
assertThat(schedulerFactory.isAutoStartup()).isFalse();
assertThat(schedulerFactory).hasFieldOrPropertyWithValue("startupDelay", 60);
assertThat(schedulerFactory).hasFieldOrPropertyWithValue("waitForJobsToCompleteOnShutdown", true);
assertThat(schedulerFactory).hasFieldOrPropertyWithValue("overwriteExistingJobs", true);
});
}
use of org.springframework.scheduling.quartz.SchedulerFactoryBean in project engine by craftercms.
the class SchedulingUtils method createScheduler.
public static Scheduler createScheduler(String schedulerName, Executor threaPoolExecutor) throws SchedulerException {
try {
SchedulerFactoryBean schedulerFactoryBean = new SchedulerFactoryBean();
schedulerFactoryBean.setSchedulerName(schedulerName);
schedulerFactoryBean.setTaskExecutor(threaPoolExecutor);
schedulerFactoryBean.afterPropertiesSet();
return schedulerFactoryBean.getObject();
} catch (Exception e) {
throw new SchedulerException("Unable to create scheduler", e);
}
}
Aggregations