Skip to content

Commit

Permalink
refactor: Tasklet을 Bean으로 등록하여 의존성 주입 방법으로 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
Hchanghyeon committed Dec 2, 2023
1 parent ded8ea4 commit cc5197b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 16 deletions.
18 changes: 2 additions & 16 deletions src/main/java/kr/pickple/back/batch/BatchConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,16 @@
import org.springframework.batch.core.job.builder.JobBuilder;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.core.step.builder.StepBuilder;
import org.springframework.batch.core.step.tasklet.Tasklet;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.PlatformTransactionManager;

import kr.pickple.back.game.repository.GameRepository;
import lombok.RequiredArgsConstructor;

@Configuration
@RequiredArgsConstructor
public class BatchConfig extends DefaultBatchConfiguration {

private final GameRepository gameRepository;

@Bean
public Job job(
final JobRepository jobRepository,
Expand All @@ -32,20 +28,10 @@ public Job job(
.build();
}

@Bean
public Tasklet gameClosedTasklet() {
return new GameClosedTasklet(gameRepository);
}

@Bean
public Tasklet gameEndedTasklet() {
return new GameEndedTasklet(gameRepository);
}

@Bean
public Step updateGameStatusToClosedStep(
final JobRepository jobRepository,
final Tasklet gameClosedTasklet,
final GameClosedTasklet gameClosedTasklet,
final PlatformTransactionManager transactionManager
) {
return new StepBuilder("updateGameStatusToClosedStep", jobRepository)
Expand All @@ -56,7 +42,7 @@ public Step updateGameStatusToClosedStep(
@Bean
public Step updateGameStatusToEndedStep(
final JobRepository jobRepository,
final Tasklet gameEndedTasklet,
final GameEndedTasklet gameEndedTasklet,
final PlatformTransactionManager transactionManager
) {
return new StepBuilder("updateGameStatusToEndedStep", jobRepository)
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/kr/pickple/back/batch/GameClosedTasklet.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@
import org.springframework.batch.core.scope.context.ChunkContext;
import org.springframework.batch.core.step.tasklet.Tasklet;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.stereotype.Component;

import kr.pickple.back.game.domain.Game;
import kr.pickple.back.game.repository.GameRepository;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@Component
@RequiredArgsConstructor
public class GameClosedTasklet implements Tasklet {

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/kr/pickple/back/batch/GameEndedTasklet.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@
import org.springframework.batch.core.scope.context.ChunkContext;
import org.springframework.batch.core.step.tasklet.Tasklet;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.stereotype.Component;

import kr.pickple.back.game.domain.Game;
import kr.pickple.back.game.repository.GameRepository;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@Component
@RequiredArgsConstructor
public class GameEndedTasklet implements Tasklet {

Expand Down

0 comments on commit cc5197b

Please sign in to comment.