-
Notifications
You must be signed in to change notification settings - Fork 2
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
[#62] feat : 선착순 쿠폰 발행 실패 -> 쿠폰 발행 배치 구현 #65
base: develop
Are you sure you want to change the base?
Conversation
private final EntityManagerFactory entityManagerFactory; | ||
private final CouponBatchWriterRepository couponBatchWriterRepository; | ||
|
||
private static final int chunkSize = 10; |
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.
말씀 드렸지만, chunkSize는 파라미터로 받도록 하는게 운영할 때 유연해서 유용합니다.
String sql = "INSERT INTO coupon_issue (coupon_issue_token, member_id, coupon_id, used_yn, created_at, used_at) VALUES (UUID_TO_BIN(?), ?, ?, ?, ?, ?)"; | ||
|
||
jdbcTemplate.batchUpdate(sql, | ||
new BatchPreparedStatementSetter() { |
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.
👍
[생각해보기]
|
@Override | ||
public void setValues(PreparedStatement ps, int i) throws SQLException { | ||
CouponIssueFailedEntity entity = couponIssueFailedEntities.get(i); | ||
ps.setObject(1, entity.getId()); |
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.
매직넘버 이네요.. 매직 넘버가 어떤 문제가 있을지 찾아보시면 좋을것 같습니다.
master: | ||
jdbc-url: jdbc:mysql://118.67.135.217:32770/goodchoice | ||
username: root | ||
password: 1234 |
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.
실무에서는 이런 민감 정보는 key 관리 시스템에 위임 합니다.
} | ||
|
||
@Test | ||
void failedCouponJob() throws Exception { |
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.
저번처럼 해피케이스만 있네요? ㅎㅎ
말씀드렸지만 오히려 실패 했을때, 트랜잭션이 롤백되는지 확인하고
데이터 정합성 이슈가 없는지 동작 체킹하는게 더 중요합니다.
쿠폰 발행이 실패 된 케이스가 정상적으로 선착순이 안되서 실패 할 수도 있을텐데 그건 다시 배치로 발행하면 안되는거 잖아요? 정책으로 맞지 않을거 같은데 검토가 필요할것 같습니다. |
스프링 배치 메트릭 수집 및 그라파나 대쉬보드 구성해보고 |
작업 요약
작업 내용
선착순 쿠폰 발행 실패 -> 쿠폰 발행 배치로 쿠폰 발행
read 는 쿼리 조회를 zero offset 으로 조회 했고, write는 배치 insert를 사용 했습니다.