Skip to content

Commit 4563be8

Browse files
committed
feat: 월별/주간별 job config 추가
1 parent 904ef24 commit 4563be8

2 files changed

Lines changed: 118 additions & 0 deletions

File tree

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package com.loopers.batch.job.ranking;
2+
3+
import com.loopers.batch.domain.ranking.MonthlyRanking;
4+
import com.loopers.batch.listener.JobListener;
5+
import com.loopers.batch.listener.StepMonitorListener;
6+
import com.loopers.dto.RankedProduct;
7+
import lombok.RequiredArgsConstructor;
8+
import org.springframework.batch.core.Job;
9+
import org.springframework.batch.core.Step;
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.item.ItemProcessor;
15+
import org.springframework.batch.item.ItemReader;
16+
import org.springframework.batch.item.ItemWriter;
17+
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
18+
import org.springframework.context.annotation.Bean;
19+
import org.springframework.context.annotation.Configuration;
20+
import org.springframework.transaction.PlatformTransactionManager;
21+
22+
@ConditionalOnProperty(name = "spring.batch.job.name", havingValue = MonthlyRankingJobConfig.JOB_NAME)
23+
@RequiredArgsConstructor
24+
@Configuration
25+
public class MonthlyRankingJobConfig {
26+
27+
public static final String JOB_NAME = "monthlyRankingJob";
28+
private static final String STEP_NAME = "monthlyRankingStep";
29+
private static final int CHUNK_SIZE = 100;
30+
31+
private final JobRepository jobRepository;
32+
private final PlatformTransactionManager transactionManager;
33+
private final JobListener jobListener;
34+
private final StepMonitorListener stepMonitorListener;
35+
36+
private final ItemReader<RankedProduct> monthlyRankingReader;
37+
private final ItemProcessor<RankedProduct, MonthlyRanking> monthlyRankingProcessor;
38+
private final ItemWriter<MonthlyRanking> monthlyRankingWriter;
39+
40+
@Bean(JOB_NAME)
41+
public Job monthlyRankingJob() {
42+
return new JobBuilder(JOB_NAME, jobRepository)
43+
.incrementer(new RunIdIncrementer())
44+
.start(monthlyRankingStep())
45+
.listener(jobListener)
46+
.build();
47+
}
48+
49+
@Bean(STEP_NAME)
50+
public Step monthlyRankingStep() {
51+
return new StepBuilder(STEP_NAME, jobRepository)
52+
.<RankedProduct, MonthlyRanking>chunk(CHUNK_SIZE, transactionManager)
53+
.reader(monthlyRankingReader)
54+
.processor(monthlyRankingProcessor)
55+
.writer(monthlyRankingWriter)
56+
.listener(stepMonitorListener)
57+
.build();
58+
}
59+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package com.loopers.batch.job.ranking;
2+
3+
import com.loopers.batch.domain.ranking.WeeklyRanking;
4+
import com.loopers.batch.listener.JobListener;
5+
import com.loopers.batch.listener.StepMonitorListener;
6+
import com.loopers.dto.RankedProduct;
7+
import lombok.RequiredArgsConstructor;
8+
import org.springframework.batch.core.Job;
9+
import org.springframework.batch.core.Step;
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.item.ItemProcessor;
15+
import org.springframework.batch.item.ItemReader;
16+
import org.springframework.batch.item.ItemWriter;
17+
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
18+
import org.springframework.context.annotation.Bean;
19+
import org.springframework.context.annotation.Configuration;
20+
import org.springframework.transaction.PlatformTransactionManager;
21+
22+
@ConditionalOnProperty(name = "spring.batch.job.name", havingValue = WeeklyRankingJobConfig.JOB_NAME)
23+
@RequiredArgsConstructor
24+
@Configuration
25+
public class WeeklyRankingJobConfig {
26+
27+
public static final String JOB_NAME = "weeklyRankingJob";
28+
private static final String STEP_NAME = "weeklyRankingStep";
29+
private static final int CHUNK_SIZE = 100;
30+
31+
private final JobRepository jobRepository;
32+
private final PlatformTransactionManager transactionManager;
33+
private final JobListener jobListener;
34+
private final StepMonitorListener stepMonitorListener;
35+
36+
private final ItemReader<RankedProduct> weeklyRankingReader;
37+
private final ItemProcessor<RankedProduct, WeeklyRanking> weeklyRankingProcessor;
38+
private final ItemWriter<WeeklyRanking> weeklyRankingWriter;
39+
40+
@Bean(JOB_NAME)
41+
public Job weeklyRankingJob() {
42+
return new JobBuilder(JOB_NAME, jobRepository)
43+
.incrementer(new RunIdIncrementer())
44+
.start(weeklyRankingStep())
45+
.listener(jobListener)
46+
.build();
47+
}
48+
49+
@Bean(STEP_NAME)
50+
public Step weeklyRankingStep() {
51+
return new StepBuilder(STEP_NAME, jobRepository)
52+
.<RankedProduct, WeeklyRanking>chunk(CHUNK_SIZE, transactionManager)
53+
.reader(weeklyRankingReader)
54+
.processor(weeklyRankingProcessor)
55+
.writer(weeklyRankingWriter)
56+
.listener(stepMonitorListener)
57+
.build();
58+
}
59+
}

0 commit comments

Comments
 (0)