Search in sources :

Example 21 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(200);
    } 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 22 with 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;
}
Also used : JobDetail(org.quartz.JobDetail) Trigger(org.quartz.Trigger) SpringBeanJobFactory(org.springframework.scheduling.quartz.SpringBeanJobFactory) SchedulerFactoryBean(org.springframework.scheduling.quartz.SchedulerFactoryBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) SchedulerFactoryBean(org.springframework.scheduling.quartz.SchedulerFactoryBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 23 with 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());
    });
}
Also used : SchedulerFactoryBean(org.springframework.scheduling.quartz.SchedulerFactoryBean) Test(org.junit.jupiter.api.Test)

Example 24 with SchedulerFactoryBean

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);
    });
}
Also used : SchedulerFactoryBean(org.springframework.scheduling.quartz.SchedulerFactoryBean) Test(org.junit.jupiter.api.Test)

Example 25 with SchedulerFactoryBean

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);
    }
}
Also used : SchedulerException(org.quartz.SchedulerException) SchedulerFactoryBean(org.springframework.scheduling.quartz.SchedulerFactoryBean) SchedulerException(org.quartz.SchedulerException)

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