33 lines
1.2 KiB
Java
33 lines
1.2 KiB
Java
|
|
package com.snp.batch.service;
|
||
|
|
|
||
|
|
import com.snp.batch.global.model.BatchApiLog;
|
||
|
|
import com.snp.batch.global.repository.BatchApiLogRepository;
|
||
|
|
import lombok.RequiredArgsConstructor;
|
||
|
|
import lombok.extern.slf4j.Slf4j;
|
||
|
|
import org.springframework.scheduling.annotation.Async;
|
||
|
|
import org.springframework.stereotype.Service;
|
||
|
|
import org.springframework.transaction.annotation.Propagation;
|
||
|
|
import org.springframework.transaction.annotation.Transactional;
|
||
|
|
|
||
|
|
@Service
|
||
|
|
@RequiredArgsConstructor
|
||
|
|
@Slf4j
|
||
|
|
public class BatchApiLogService {
|
||
|
|
private final BatchApiLogRepository batchApiLogRepository;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 비동기로 API 로그를 저장합니다.
|
||
|
|
* propagation = Propagation.REQUIRES_NEW 를 사용하여
|
||
|
|
* 메인 배치가 실패(Rollback)하더라도 로그는 저장되도록 설정합니다.
|
||
|
|
*/
|
||
|
|
@Async("apiLogExecutor") // 설정한 스레드 풀 사용
|
||
|
|
@Transactional(propagation = Propagation.REQUIRES_NEW)
|
||
|
|
public void saveLog(BatchApiLog logEntry) {
|
||
|
|
try {
|
||
|
|
batchApiLogRepository.save(logEntry);
|
||
|
|
} catch (Exception e) {
|
||
|
|
// 로그 저장 실패가 배치를 중단시키지 않도록 여기서 예외 처리
|
||
|
|
log.error("API 로그 저장 실패: {}", e.getMessage());
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|