|
| 1 | +package com.loopers.batch.job.demo; |
| 2 | + |
| 3 | +import com.loopers.batch.job.demo.step.DemoTasklet; |
| 4 | +import com.loopers.batch.listener.JobListener; |
| 5 | +import com.loopers.batch.listener.StepMonitorListener; |
| 6 | +import lombok.RequiredArgsConstructor; |
| 7 | +import org.springframework.batch.core.Job; |
| 8 | +import org.springframework.batch.core.Step; |
| 9 | +import org.springframework.batch.core.configuration.annotation.JobScope; |
| 10 | +import org.springframework.batch.core.job.builder.JobBuilder; |
| 11 | +import org.springframework.batch.core.launch.support.RunIdIncrementer; |
| 12 | +import org.springframework.batch.core.repository.JobRepository; |
| 13 | +import org.springframework.batch.core.step.builder.StepBuilder; |
| 14 | +import org.springframework.batch.support.transaction.ResourcelessTransactionManager; |
| 15 | +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; |
| 16 | +import org.springframework.context.annotation.Bean; |
| 17 | +import org.springframework.context.annotation.Configuration; |
| 18 | + |
| 19 | +@ConditionalOnProperty(name = "spring.batch.job.name", havingValue = DemoJobConfig.JOB_NAME) |
| 20 | +@RequiredArgsConstructor |
| 21 | +@Configuration |
| 22 | +public class DemoJobConfig { |
| 23 | + public static final String JOB_NAME = "demoJob"; |
| 24 | + private static final String STEP_DEMO_SIMPLE_TASK_NAME = "demoSimpleTask"; |
| 25 | + |
| 26 | + private final JobRepository jobRepository; |
| 27 | + private final JobListener jobListener; |
| 28 | + private final StepMonitorListener stepMonitorListener; |
| 29 | + private final DemoTasklet demoTasklet; |
| 30 | + |
| 31 | + @Bean(JOB_NAME) |
| 32 | + public Job demoJob() { |
| 33 | + return new JobBuilder(JOB_NAME, jobRepository) |
| 34 | + .incrementer(new RunIdIncrementer()) |
| 35 | + .start(categorySyncStep()) |
| 36 | + .listener(jobListener) |
| 37 | + .build(); |
| 38 | + } |
| 39 | + |
| 40 | + @JobScope |
| 41 | + @Bean(STEP_DEMO_SIMPLE_TASK_NAME) |
| 42 | + public Step categorySyncStep() { |
| 43 | + return new StepBuilder(STEP_DEMO_SIMPLE_TASK_NAME, jobRepository) |
| 44 | + .tasklet(demoTasklet, new ResourcelessTransactionManager()) |
| 45 | + .listener(stepMonitorListener) |
| 46 | + .build(); |
| 47 | + } |
| 48 | +} |
0 commit comments