-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[#243] Spring Batch를 사용한 게스트 모집 글 상태 변경 자동화 #254
Conversation
public Job job( | ||
final JobRepository jobRepository, | ||
final Step updateGameStatusToClosedStep, | ||
final Step updateGameStatusToEndedStep | ||
) { | ||
return new JobBuilder("updateGameStatus", jobRepository) | ||
.start(updateGameStatusToClosedStep) | ||
.next(updateGameStatusToEndedStep) | ||
.build(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
하나의 Job을 의미하며
.start()에 들어가는 Step은 게임 상태를 모집 중
-> 모집 마감
으로 변경하는 Step이고
.next()에 들어가는 Step은 게임 상태를 모집 마감
-> 경기 종료
로 변경하는 Step입니다.
한마디로 하나의 Job안에 2개의 Step이 들어있고 .start()를 이용하여 첫번째 Step을 진행하고 .next()를 이용하여 두번째 Step이 진행됩니다!
@Bean | ||
public Tasklet gameClosedTasklet() { | ||
return new GameClosedTasklet(gameRepository); | ||
} | ||
|
||
@Bean | ||
public Tasklet gameEndedTasklet() { | ||
return new GameEndedTasklet(gameRepository); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tasklet 객체는 Step에 사용되는 실제로 배치 작업을 수행하는 객체 입니다.
@Scheduled(cron = "0 0/30 * * * *") | ||
public void runJob() { | ||
try { | ||
jobLauncher.run( | ||
job, | ||
new JobParametersBuilder() | ||
.addString("dateTime", LocalDateTime.now().toString()) | ||
.toJobParameters() | ||
); | ||
} catch ( | ||
JobExecutionAlreadyRunningException | | ||
JobInstanceAlreadyCompleteException | | ||
JobParametersInvalidException | | ||
JobRestartException e | ||
) { | ||
log.error("[Scheduler - Batch] run job exception: ", e); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
매 30분마다 jobLauncher에 의해 설정 해둔 Job이 수행됩니다.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
창현님 설명 상세하게 작성해주시고, 라이브로도 한 번 설명해주셔서 잘 이해할 수 있었습니다. 짱짱맨~~
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
spring 5로 넘어오면서 레퍼런스가 많이 없어서 batch 까지는 못할것 같다고 생각했는데.. 역시;;
굿굿 👍
public class BatchConfig extends DefaultBatchConfiguration { | ||
|
||
@Bean | ||
public Job job( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
현재는 job이 하나지만, 여러개로 늘어날 가능성을 고려해 네이밍하면 좋을것 같아요
BatchConfig -> 어쩌구BatchConfig
그리고 job bean도 중복될수 있으니 name 파라미터나 메소드명으로 네이밍 신경쓰기~!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
말씀하신대로 확장 가능성을 고려하여 Class 파일명, 메서드명 모두 수정했습니다! 감사합니다 👍👍
Kudos, SonarCloud Quality Gate passed! |
👨💻 작업 사항
📑 PR 개요
✅ 작업 목록
🙏 리뷰어에게
Prefix
P1
: 꼭 반영해주세요 (Request changes)P2
: 적극적으로 고려해주세요 (Request changes)P3
: 웬만하면 반영해 주세요 (Comment)P4
: 반영해도 좋고 넘어가도 좋습니다 (Approve)P5
: 그냥 사소한 의견입니다 (Approve)