Skip to content

Commit d1693f0

Browse files
committed
feat(ranking): 월간 및 주간 랭킹 엔티티 필드명 수정
- rank_position을 base_rank_position으로 변경 - year_month를 base_year_month로 변경 - 로그 메시지 개선 및 예외 처리 강화
1 parent 2dffa78 commit d1693f0

4 files changed

Lines changed: 27 additions & 21 deletions

File tree

apps/commerce-batch/src/main/java/com/loopers/batch/job/ranking/writer/MonthlyRankWriter.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,30 +32,33 @@ public class MonthlyRankWriter implements ItemWriter<RankingAggregation> {
3232
@Override
3333
public void write(Chunk<? extends RankingAggregation> chunk) throws Exception {
3434
List<? extends RankingAggregation> items = chunk.getItems();
35-
35+
3636
if (items.isEmpty()) {
37-
log.info("저장할 월간 랭킹 데이터가 없습니다: yearMonth={}", yearMonth);
37+
log.info("[Batch-Ranking] 저장할 월간 랭킹 데이터가 없습니다. (yearMonth: {})", yearMonth);
3838
return;
3939
}
4040

41-
log.info("월간 랭킹 저장 시작: yearMonth={}, 저장할 데이터 수={}", yearMonth, items.size());
41+
int targetCount = items.size();
42+
log.info("[Batch-Ranking] 월간 랭킹 저장 프로세스 시작 (yearMonth: {}, 대상 건수: {})", yearMonth, targetCount);
4243

4344
try {
4445
// 1. 기존 데이터 삭제 (멱등성 보장)
4546
long deletedCount = monthlyRankRepository.deleteByYearMonth(yearMonth);
46-
log.info("기존 월간 랭킹 데이터 삭제: yearMonth={}, 삭제된 수={}", yearMonth, deletedCount);
47+
log.info("[Batch-Ranking] 기존 데이터 클렌징 완료 (yearMonth: {}, 삭제 건수: {})", yearMonth, deletedCount);
4748

4849
// 2. 새로운 데이터 저장
4950
List<MonthlyRankEntity> entities = items.stream()
5051
.map(this::convertToEntity)
5152
.toList();
5253

53-
List<MonthlyRankEntity> savedEntities = monthlyRankRepository.saveAll(entities);
54-
log.info("월간 랭킹 저장 완료: yearMonth={}, 저장된 수={}", yearMonth, savedEntities.size());
54+
monthlyRankRepository.saveAll(entities);
55+
log.info("[Batch-Ranking] 월간 랭킹 저장 성공 (yearMonth: {}, 저장 건수: {})", yearMonth, entities.size());
5556

5657
} catch (Exception e) {
57-
log.error("월간 랭킹 저장 중 오류 발생: yearMonth={}", yearMonth, e);
58-
throw new RuntimeException("월간 랭킹 저장 실패", e);
58+
// 상세한 컨텍스트를 포함한 에러 로그
59+
log.error("[Batch-Ranking] 월간 랭킹 저장 중 예외 발생! (yearMonth: {}, 처리 중이던 건수: {}) - 원인: {}",
60+
yearMonth, targetCount, e.getMessage(), e);
61+
throw e;
5962
}
6063
}
6164

@@ -71,4 +74,4 @@ private MonthlyRankEntity convertToEntity(RankingAggregation aggregation) {
7174
aggregation.getRankPosition()
7275
);
7376
}
74-
}
77+
}

apps/commerce-batch/src/main/java/com/loopers/batch/job/ranking/writer/WeeklyRankWriter.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,30 +32,33 @@ public class WeeklyRankWriter implements ItemWriter<RankingAggregation> {
3232
@Override
3333
public void write(Chunk<? extends RankingAggregation> chunk) throws Exception {
3434
List<? extends RankingAggregation> items = chunk.getItems();
35-
35+
3636
if (items.isEmpty()) {
37-
log.info("저장할 주간 랭킹 데이터가 없습니다: yearWeek={}", yearWeek);
37+
log.info("[Batch-Ranking] 저장할 주간 랭킹 데이터가 없습니다. (yearWeek: {})", yearWeek);
3838
return;
3939
}
4040

41-
log.info("주간 랭킹 저장 시작: yearWeek={}, 저장할 데이터 수={}", yearWeek, items.size());
41+
int targetCount = items.size();
42+
log.info("[Batch-Ranking] 주간 랭킹 저장 프로세스 시작 (yearWeek: {}, 대상 건수: {})", yearWeek, targetCount);
4243

4344
try {
4445
// 1. 기존 데이터 삭제 (멱등성 보장)
4546
long deletedCount = weeklyRankRepository.deleteByYearWeek(yearWeek);
46-
log.info("기존 주간 랭킹 데이터 삭제: yearWeek={}, 삭제된 수={}", yearWeek, deletedCount);
47+
log.info("[Batch-Ranking] 기존 데이터 클렌징 완료 (yearWeek: {}, 삭제 건수: {})", yearWeek, deletedCount);
4748

4849
// 2. 새로운 데이터 저장
4950
List<WeeklyRankEntity> entities = items.stream()
5051
.map(this::convertToEntity)
5152
.toList();
5253

53-
List<WeeklyRankEntity> savedEntities = weeklyRankRepository.saveAll(entities);
54-
log.info("주간 랭킹 저장 완료: yearWeek={}, 저장된 수={}", yearWeek, savedEntities.size());
54+
weeklyRankRepository.saveAll(entities);
55+
log.info("[Batch-Ranking] 주간 랭킹 저장 성공 (yearWeek: {}, 저장 건수: {})", yearWeek, entities.size());
5556

5657
} catch (Exception e) {
57-
log.error("주간 랭킹 저장 중 오류 발생: yearWeek={}", yearWeek, e);
58-
throw new RuntimeException("주간 랭킹 저장 실패", e);
58+
// 상세한 컨텍스트를 포함한 에러 로그
59+
log.error("[Batch-Ranking] 주간 랭킹 저장 중 예외 발생! (yearWeek: {}, 처리 중이던 건수: {}) - 원인: {}",
60+
yearWeek, targetCount, e.getMessage(), e);
61+
throw e; // 예외를 그대로 던져서 Batch Step이 실패 상태가 되도록 위임
5962
}
6063
}
6164

@@ -71,4 +74,4 @@ private WeeklyRankEntity convertToEntity(RankingAggregation aggregation) {
7174
aggregation.getRankPosition()
7275
);
7376
}
74-
}
77+
}

modules/jpa/src/main/java/com/loopers/domain/ranking/MonthlyRankEntity.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
@Table(
2121
name = "mv_product_rank_monthly",
2222
indexes = {
23-
@Index(name = "idx_year_month_rank", columnList = "year_month, rank_position")
23+
@Index(name = "idx_year_month_rank", columnList = "base_year_month, base_rank_position으로")
2424
}
2525
)
2626
@Getter
@@ -45,7 +45,7 @@ public class MonthlyRankEntity {
4545
@Column(name = "total_score", nullable = false)
4646
private long totalScore;
4747

48-
@Column(name = "rank_position", nullable = false)
48+
@Column(name = "base_rank_position", nullable = false)
4949
private long rankPosition;
5050

5151
@Column(name = "created_at", nullable = false)

modules/jpa/src/main/java/com/loopers/domain/ranking/MonthlyRankId.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class MonthlyRankId implements Serializable {
2222
@Column(name = "product_id", nullable = false)
2323
private Long productId;
2424

25-
@Column(name = "year_month", nullable = false, length = 7)
25+
@Column(name = "base_year_month", nullable = false, length = 7)
2626
private String yearMonth; // e.g., "2024-12"
2727

2828
private MonthlyRankId(Long productId, String yearMonth) {

0 commit comments

Comments
 (0)