org.springframework.boot.autoconfigure.quartz.JobStoreType Java Examples

The following examples show how to use org.springframework.boot.autoconfigure.quartz.JobStoreType. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JobServerProperties.java    From spring-boot-starter-micro-job with Apache License 2.0 6 votes vote down vote up
/**
 * 如果并未自定义配置信息
 * 使用默认的配置信息
 *
 * @return
 */
public QuartzConfigProperties getQuartz() {
    if (quartz == null) {
        // init
        quartz = new QuartzConfigProperties();

        // 设置任务存储方式为数据库方式
        quartz.setJobStoreType(JobStoreType.JDBC);

        // 设置schema初始化模式
        quartz.getJdbc().setInitializeSchema(DataSourceInitializationMode.EMBEDDED);

        // 设置属性配置
        quartz.getProperties().put("org.quartz.scheduler.instanceName", "jobScheduler");
        quartz.getProperties().put("org.quartz.scheduler.instanceId", "AUTO");
        quartz.getProperties().put("org.quartz.jobStore.class", "org.quartz.impl.jdbcjobstore.JobStoreTX");
        quartz.getProperties().put("org.quartz.jobStore.driverDelegateClass", "org.quartz.impl.jdbcjobstore.StdJDBCDelegate");
        quartz.getProperties().put("org.quartz.jobStore.tablePrefix", "JOB_NODE_QRTZ_");
        quartz.getProperties().put("org.quartz.jobStore.isClustered", "true");
        quartz.getProperties().put("org.quartz.jobStore.clusterCheckinInterval", "20000");
        quartz.getProperties().put("org.quartz.threadPool.threadsInheritContextClassLoaderOfInitializingThread", "true");
    }
    return quartz;
}
 
Example #2
Source File: ApiBootQuartzAutoConfiguration.java    From beihu-boot with Apache License 2.0 5 votes vote down vote up
/**
 * properties needed to initialize Jdbc mode
 *
 * @param properties ApiBoot Quartz Properties
 * @return SchedulerFactoryBeanCustomizer
 */
@Bean
@Order(0)
public SchedulerFactoryBeanCustomizer jobPropertiesCustomizer(ApiBootQuartzProperties properties) {
    return schedulerFactoryBean -> {
        // jdbc away
        if (properties.getJobStoreType() == JobStoreType.JDBC) {

            ApiBootQuartzProperties.Prop prop = properties.getProp();
            // get prop class declared fields
            Field[] fields = prop.getClass().getDeclaredFields();
            Arrays.stream(fields).forEach(field -> {
                try {
                    field.setAccessible(true);
                    String value = String.valueOf(field.get(prop));
                    PropKey propKey = field.getDeclaredAnnotation(PropKey.class);

                    // put prop to quartz properties
                    properties.getProperties().put(propKey.value(), value);
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                }

            });
        }
    };
}
 
Example #3
Source File: ApiBootQuartzAutoConfiguration.java    From beihu-boot with Apache License 2.0 5 votes vote down vote up
@Bean
@Order(1)
public SchedulerFactoryBeanCustomizer jobDataSourceCustomizer(ApiBootQuartzProperties properties, DataSource dataSource, @QuartzDataSource ObjectProvider<DataSource> quartzDataSource, ObjectProvider<PlatformTransactionManager> transactionManager) {
    return (schedulerFactoryBean) -> {
        if (properties.getJobStoreType() == JobStoreType.JDBC) {
            DataSource dataSourceToUse = this.getDataSource(dataSource, quartzDataSource);
            schedulerFactoryBean.setDataSource(dataSourceToUse);
            PlatformTransactionManager txManager = transactionManager.getIfUnique();
            if (txManager != null) {
                schedulerFactoryBean.setTransactionManager(txManager);
            }
        }

    };
}
 
Example #4
Source File: Neutron.java    From Milkomeda with MIT License 5 votes vote down vote up
/**
 * 创建JOB
 * @param jobName   job名称
 * @param group     job组
 * @param jobClass  job类
 * @param description job描述
 * @return  jobDetail
 */
public static JobDetail createJobDetail(String jobName, String group, Class<? extends Job> jobClass, String description) {
    return JobBuilder.newJob(jobClass)
            .withIdentity(jobName, group)
             .withDescription(description)
            // 持久化到数据库
             .storeDurably(NeutronHolder.getProps().getJobStoreType() == JobStoreType.JDBC)
            .build();
}
 
Example #5
Source File: ApiBootQuartzAutoConfiguration.java    From api-boot with Apache License 2.0 5 votes vote down vote up
/**
 * properties needed to initialize Jdbc mode
 *
 * @param properties ApiBoot Quartz Properties
 * @return SchedulerFactoryBeanCustomizer
 */
@Bean
@Order(0)
public SchedulerFactoryBeanCustomizer jobPropertiesCustomizer(ApiBootQuartzProperties properties) {
    return schedulerFactoryBean -> {
        // jdbc away
        if (properties.getJobStoreType() == JobStoreType.JDBC) {

            ApiBootQuartzProperties.Prop prop = properties.getProp();
            // get prop class declared fields
            Field[] fields = prop.getClass().getDeclaredFields();
            Arrays.stream(fields).forEach(field -> {
                try {
                    field.setAccessible(true);
                    String value = String.valueOf(field.get(prop));
                    PropKey propKey = field.getDeclaredAnnotation(PropKey.class);

                    // put prop to quartz properties
                    properties.getProperties().put(propKey.value(), value);
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                }

            });
        }
    };
}
 
Example #6
Source File: ApiBootQuartzAutoConfiguration.java    From api-boot with Apache License 2.0 5 votes vote down vote up
@Bean
@Order(1)
public SchedulerFactoryBeanCustomizer jobDataSourceCustomizer(ApiBootQuartzProperties properties, DataSource dataSource, @QuartzDataSource ObjectProvider<DataSource> quartzDataSource, ObjectProvider<PlatformTransactionManager> transactionManager) {
    return (schedulerFactoryBean) -> {
        if (properties.getJobStoreType() == JobStoreType.JDBC) {
            DataSource dataSourceToUse = this.getDataSource(dataSource, quartzDataSource);
            schedulerFactoryBean.setDataSource(dataSourceToUse);
            PlatformTransactionManager txManager = transactionManager.getIfUnique();
            if (txManager != null) {
                schedulerFactoryBean.setTransactionManager(txManager);
            }
        }

    };
}