Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import java.time.Clock;
import java.time.LocalDateTime;
import java.time.OffsetDateTime;
import java.time.ZoneId;
import java.time.temporal.ChronoUnit;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@
import org.springframework.transaction.PlatformTransactionManager;
import store.slackjudge.batch.tasklet.*;

import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;

@Configuration
@RequiredArgsConstructor
public class BatchConfig {
Expand All @@ -26,12 +22,17 @@ public class BatchConfig {
private final SaveSnapshotTasklet saveSnapshotTasklet;
private final BatchJobListener jobListener;

private final BatchLogger logger;


/* ===========================================
* Job 정의
* =========================================== */
/*==========================
*
*BatchConfig
* Job 정의
* @parm
* @return
* @author kimdoyeon
* @version 1.0.0
* @date 25. 12. 17.
*
==========================**/
@Bean
public Job slackJudgeBatch(
JobRepository jobRepository,
Expand All @@ -52,9 +53,18 @@ public Job slackJudgeBatch(
}


/* ===========================================
* Step01: RDB에서 유저 조회
* =========================================== */
/*==========================
*
*BatchConfig
* Step01: RDB에서 유저 조회
* @parm jobRepository : Batch job repository
* transactionManager: 트랜잭션 엔진 공통 인터페이스
* @return
* @author kimdoyeon
* @version 1.0.0
* @date 25. 12. 17.
*
==========================**/
@Bean
public Step loadAllUsersStep(
JobRepository jobRepository,
Expand All @@ -74,9 +84,18 @@ public ExecutionContextPromotionListener promoteUsers() {
}


/* ===========================================
* Step02: Mongo Snapshot 조회
* =========================================== */
/*==========================
*
*BatchConfig
* Step02: Mongo Snapshot 조회
* @parm jobRepository : Batch job repository
* transactionManager: 트랜잭션 엔진 공통 인터페이스
* @return
* @author kimdoyeon
* @version 1.0.0
* @date 25. 12. 17.
*
==========================**/
@Bean
public Step loadSnapshotStep(
JobRepository jobRepository,
Expand All @@ -96,9 +115,18 @@ public ExecutionContextPromotionListener promoteSnapshots() {
}


/* ===========================================
* Step03: solved.ac 유저 정보 조회
* =========================================== */
/*==========================
*
*BatchConfig
* Step03: solved.ac 유저 정보 조회
* @parm jobRepository : Batch job repository
* transactionManager: 트랜잭션 엔진 공통 인터페이스
* @return
* @author kimdoyeon
* @version 1.0.0
* @date 25. 12. 17.
*
==========================**/
@Bean
public Step fetchSolvedAcUserInfoStep(
JobRepository jobRepository,
Expand All @@ -118,9 +146,18 @@ public ExecutionContextPromotionListener promoteUserSolvedInfo() {
}


/* ===========================================
* Step04: 변경 감지
* =========================================== */
/*==========================
*
*BatchConfig
* Step04: 변경 감지
* @parm jobRepository : Batch job repository
* transactionManager: 트랜잭션 엔진 공통 인터페이스
* @return
* @author kimdoyeon
* @version 1.0.0
* @date 25. 12. 17.
*
==========================**/
@Bean
public Step detectAndUpdateUserTierAndProblemStep(
JobRepository jobRepository,
Expand All @@ -140,9 +177,18 @@ public ExecutionContextPromotionListener promoteCurrentSnapshot() {
}


/* ===========================================
* Step05: Snapshot 저장
* =========================================== */
/*==========================
*
*BatchConfig
* Step05: Snapshot 저장
* @parm jobRepository : Batch job repository
* transactionManager: 트랜잭션 엔진 공통 인터페이스
* @return
* @author kimdoyeon
* @version 1.0.0
* @date 25. 12. 17.
*
==========================**/
@Bean
public Step saveSnapshotStep(
JobRepository jobRepository,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import java.time.Duration;
import java.time.LocalDateTime;
import java.util.Objects;


@Component
@RequiredArgsConstructor
Expand All @@ -24,6 +24,17 @@ public class BatchJobListener {
private final SlackNotificationService notificationService;
private final CalculateSnapShotDate calculateSnapShotDate;

/*==========================
*
* BatchJobListener
* BatchJob 실행 이전 수행 작업 정의
* @parm jobExecution : Job 실행 중에 발생 정보 저장 객체
* @return
* @author kimdoyeon
* @version 1.0.0
* @date 25. 12. 17.
*
==========================**/
@BeforeJob
public void beforeJob(JobExecution jobExecution) {
logger.jobStart(jobExecution.getJobInstance().getJobName());
Expand All @@ -39,6 +50,17 @@ public void beforeJob(JobExecution jobExecution) {
);
}

/*==========================
*
* BatchJobListener
* BatchJob 실행 이후 수행 작업 정의
* @parm jobExecution : Job 실행 중에 발생 정보 저장 객체
* @return
* @author kimdoyeon
* @version 1.0.0
* @date 25. 12. 17.
*
==========================**/
@AfterJob
public void afterJob(JobExecution jobExecution) {
ExecutionContext ctx = jobExecution.getExecutionContext();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@
@Component
@ReadingConverter
public class DateToLocalDateTimeKstConverter implements Converter<Date, LocalDateTime> {
/*==========================
*
*DateToLocalDateTimeKstConverter
* UTC->KST로 변환합니다.
* @parm source : 입력 날짜
* @return UTC로 변환된 LocalDateTime
* @author kimdoyeon
* @version 1.0.0
* @date 25. 12. 17.
*
==========================**/
@Override
public LocalDateTime convert(Date source) {
//UTC->KST
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package store.slackjudge.batch.config.converter;

import org.bson.json.StrictJsonWriter;
import org.springframework.core.convert.converter.Converter;
import org.springframework.data.convert.WritingConverter;
import org.springframework.stereotype.Component;

import java.sql.Timestamp;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;
Expand All @@ -16,7 +13,17 @@
@Component
@WritingConverter
public class LocalDateTimeToDateKstConverter implements Converter<LocalDateTime, Date> {

/*==========================
*
*LocalDateTimeToDateKstConverter
* UTC -> KST로 변환합니다.
* @parm source:UTC 기준 시간대
* @return KST 변환된 시간
* @author kimdoyeon
* @version 1.0.0
* @date 25. 12. 17.
*
==========================**/
@Override
public Date convert(LocalDateTime source) {
//KST->UTC
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@

import java.io.Serializable;

/**
* 유저 정보 DTO
* @param baekJoonId 백준 아이디
* @param userId 유저 PK
* @param baekJoonTier 백준 티어
*/
public record UserInfo(
String baekJoonId,
Long userId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
@AllArgsConstructor(access = AccessLevel.PACKAGE)
@RequiredArgsConstructor
@Getter
/**
* Snapshot document 복합키
*/
public class SnapShotId implements Serializable {
private String bojId;
private LocalDateTime snapShotAt;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
@Getter
@RequiredArgsConstructor
@AllArgsConstructor(access = AccessLevel.PACKAGE)
/**
* 유저가 푼 문제 스냅샷 document
*/
public class UserSolvedSnapShotDocument implements Serializable {
//(백준 아이디, 배치 동작 시간) 복합 키
@Id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@

/**
* Document 저장용 DTO
* @param bojId 백준아이디
* @param snapShotAt 스냅셧 기준일
* @param solvedProblemIds 유저가 푼 문제 번호 리스트
* @param solvedCount 유저가 푼 문제 수
* @param tier 백준 티어
* @param userId 유저 아이디 PK
* @param rating 유저 점수(solved.ac 기준)
*/
public record SaveSnapshot(
String bojId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,21 @@
public class SlackNotificationService {
private final SlackSender sender;
private final SlackMessageFactory messageFactory;

/*==========================
*
* notifyBatchStart
*
* @parm jobName 배치 Job 이름
* @parm batchTime 배치 실행 기준 시간
* @parm workerNode 배치를 실행한 워커 노드 정보
* @return void
* 배치 시작 시 Slack 알림을 전송
*
* @author kimdoyeon
* @version 1.0.0
* @date 25. 12. 17.
*
==========================**/
public void notifyBatchStart(String jobName, LocalDateTime batchTime,String workerNode){
Attachment message=messageFactory.batchStart(new BatchStartMessageSpec(
jobName, batchTime, workerNode)
Expand All @@ -24,14 +38,45 @@ public void notifyBatchStart(String jobName, LocalDateTime batchTime,String work
sender.sendMessage(message);
}

/*==========================
*
* notifyBatchSuccess
*
* @parm duration 배치 수행 시간(ms)
* @parm totalUsers 전체 처리 대상 사용자 수
* @parm newUsers 신규 사용자 수
* @parm updated 업데이트된 사용자 수
* @parm failed 실패한 사용자 수
* @parm time 배치 종료 시각
* @return void
* 배치 성공 시 처리 결과를 Slack으로 전송
*
* @author kimdoyeon
* @version 1.0.0
* @date 25. 12. 17.
*
==========================**/
public void notifyBatchSuccess(long duration,int totalUsers,int newUsers,int updated,int failed,LocalDateTime time){
Attachment message=messageFactory.batchEnd(new BatchEndMessageSpec(
"SUCCESS",duration,totalUsers,newUsers,updated,failed,time,""
));

sender.sendMessage(message);
}

/*==========================
*
* notifyBatchFailed
*
* @parm occurredAt 배치 실패 발생 시각
* @parm reason 배치 실패 사유
* @return void
* 배치 실패 시 원인 정보를 포함한 Slack 알림을 전송
*
* @author kimdoyeon
* @version 1.0.0
* @date 25. 12. 17.
*
==========================**/
public void notifyBatchFailed(LocalDateTime occurredAt,String reason){
Attachment message = messageFactory.batchEnd(
new BatchEndMessageSpec(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@
import java.time.LocalDateTime;
import java.time.ZoneId;

/**
* Batch log event DTO
* @param level 로그 레벨
* @param occurredAt 로그 발생 시각
* @param logger 로그 객체
* @param message 로그 메시지
* @param stackTrace 로그가 호출 메서드 메타 데이터
*/
public record LogEventMessageSpec(
String level,
LocalDateTime occurredAt,
Expand Down
Loading