Merge branch 'bo_sms-auto-send' into 'dev'

[배치] hostName -> ip로 변경, batch_check 테이블 create_at, created_ip 칼럼 추가

See merge request korea-research/korea-research!148
This commit is contained in:
이강선 매니저/ST
2025-07-24 01:26:04 +00:00
13 changed files with 77 additions and 70 deletions

View File

@@ -3,6 +3,7 @@ package app.module.admin.config.application.batch;
import app.module.admin.usecase.batchLog.ports.BatchLogPortIn; import app.module.admin.usecase.batchLog.ports.BatchLogPortIn;
import app.module.admin.usecase.batchLog.ports.application.domain.BatchLogType; import app.module.admin.usecase.batchLog.ports.application.domain.BatchLogType;
import app.module.core.config.application.logging.SafeLogger; import app.module.core.config.application.logging.SafeLogger;
import java.net.InetAddress;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@@ -23,25 +24,25 @@ public class BatchLogRunner {
return; return;
} }
String hostName;
try {
hostName = java.net.InetAddress.getLocalHost().getHostName();
} catch (UnknownHostException e) {
hostName = "UNKNOWN";
safeLogger.warn("호스트 이름 조회 실패", e);
}
// dev 환경 + 실제 날짜에 실행 로그 insert (RUNNING) // dev 환경 + 실제 날짜에 실행 로그 insert (RUNNING)
Long logId = batchLogPortIn.create(batchType, hostName, "RUNNING"); Long logId = batchLogPortIn.create(batchType, getIpAddress(), "RUNNING");
try { try {
action.run(); action.run();
// 성공 처리 // 성공 처리
batchLogPortIn.update(logId, hostName,"SUCCESS", null); batchLogPortIn.update(logId, getIpAddress(),"SUCCESS", null);
} catch (Exception e) { } catch (Exception e) {
// 실패 처리 // 실패 처리
batchLogPortIn.update(logId, hostName,"FAIL", e.getMessage()); batchLogPortIn.update(logId, getIpAddress(),"FAIL", e.getMessage());
safeLogger.error("[{}] 배치 실패: {}", batchType.name(), e.getMessage(), e); safeLogger.error("[{}] 배치 실패: {}", batchType.name(), e.getMessage(), e);
} }
} }
private String getIpAddress() {
try {
return InetAddress.getLocalHost().getHostAddress();
} catch (UnknownHostException e) {
return "unknown";
}
}
} }

View File

@@ -3,6 +3,7 @@ package app.module.admin.usecase.batchCheck.ports.application;
import app.module.admin.usecase.batchCheck.ports.application.domain.BatchCheckInCmd; import app.module.admin.usecase.batchCheck.ports.application.domain.BatchCheckInCmd;
import app.module.admin.usecase.batchLog.ports.BatchLogPortIn; import app.module.admin.usecase.batchLog.ports.BatchLogPortIn;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.UnknownHostException;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import app.module.admin.usecase.batchCheck.ports.application.domain.BatchCheckOutCmd; import app.module.admin.usecase.batchCheck.ports.application.domain.BatchCheckOutCmd;
import app.module.admin.usecase.batchCheck.ports.BatchCheckPortIn; import app.module.admin.usecase.batchCheck.ports.BatchCheckPortIn;
@@ -21,30 +22,30 @@ class BatchCheckService implements BatchCheckPortIn {
@Override @Override
public boolean operate(BatchCheckInCmd inCmd) { public boolean operate(BatchCheckInCmd inCmd) {
try { try {
portOut.operate(new BatchCheckOutCmd(inCmd.getType(), inCmd.getRunDate())); portOut.operate(new BatchCheckOutCmd(inCmd.getType(), inCmd.getRunDate(), getIpAddress()));
return true; return true;
} catch (DuplicateKeyException e) { } catch (DuplicateKeyException e) {
log.warn("{} 가 이미 실행 중입니다. 중복 실행을 건너뜁니다.", inCmd.getMethodName()); log.warn("[batch] {} 가 이미 실행 중입니다. 중복 실행을 건너뜁니다.", inCmd.getMethodName());
batchLogPortIn.createError(inCmd.getType(), getHostName(), "WARNING", batchLogPortIn.createError(inCmd.getType(), getIpAddress(), "WARNING",
inCmd.getMethodName() + " 가 이미 실행 중입니다. 중복 실행을 건너뜁니다."); "[batch]" + inCmd.getMethodName() + " 가 이미 실행 중입니다. 중복 실행을 건너뜁니다.");
return false; return false;
} catch (Exception e) { } catch (Exception e) {
log.error("중복 실행 체크 예외 발생 : {} / {}", inCmd.getMethodName(), e.getMessage(), e); log.error("[batch] 중복 실행 체크 예외 발생 : {} / {}", inCmd.getMethodName(), e.getMessage(), e);
batchLogPortIn.createError(inCmd.getType(), getHostName(), "ERROR", batchLogPortIn.createError(inCmd.getType(), getIpAddress(), "ERROR",
inCmd.getMethodName() + " 중복 체크 중 예외 발생: " + e.getMessage()); "[batch]" + inCmd.getMethodName() + " 중복 체크 중 예외 발생: " + e.getMessage());
return false; return false;
} }
} }
private String getHostName() { private String getIpAddress() {
try { try {
return InetAddress.getLocalHost().getHostName(); return InetAddress.getLocalHost().getHostAddress();
} catch (Exception e) { } catch (UnknownHostException e) {
return "unknown"; return "unknown";
} }
} }

View File

@@ -14,4 +14,5 @@ import lombok.Setter;
public class BatchCheckOutCmd { public class BatchCheckOutCmd {
private BatchLogType type; private BatchLogType type;
private Date runDate; private Date runDate;
private String ip;
} }

View File

@@ -19,19 +19,19 @@ class BatchLogDao implements BatchLogPortOut {
} }
@Override @Override
public Long create(BatchLogType type, String hostName, String status) { public Long create(BatchLogType type, String ip, String status) {
BatchLogCmd cmd = new BatchLogCmd(null, type.name(), status, LocalDateTime.now(), hostName); BatchLogCmd cmd = new BatchLogCmd(null, type.name(), status, ip, LocalDateTime.now());
mapper.create(cmd); mapper.create(cmd);
return cmd.getId(); return cmd.getId();
} }
@Override @Override
public void createError(BatchLogType type, String hostName, String status, String errorMessage) { public void createError(BatchLogType type, String ip, String status, String errorMessage) {
mapper.createError(type.name(), hostName, status, errorMessage); mapper.createError(type.name(), ip, status, errorMessage);
} }
@Override @Override
public void update(Long id, String hostName, String status, String errorMessage) { public void update(Long id, String ip, String status, String errorMessage) {
mapper.update(id, hostName, status, errorMessage); mapper.update(id, ip, status, errorMessage);
} }
} }

View File

@@ -7,6 +7,6 @@ import org.apache.ibatis.annotations.Mapper;
public interface BatchLogMapper { public interface BatchLogMapper {
boolean exists(String type); boolean exists(String type);
Long create(BatchLogCmd cmd); Long create(BatchLogCmd cmd);
Long createError(String type, String hostName, String status, String errorMessage); Long createError(String type, String ip, String status, String errorMessage);
void update(Long id, String hostName, String status, String errorMessage); void update(Long id, String ip, String status, String errorMessage);
} }

View File

@@ -4,7 +4,7 @@ import app.module.admin.usecase.batchLog.ports.application.domain.BatchLogType;
public interface BatchLogPortIn { public interface BatchLogPortIn {
boolean exists(BatchLogType type); boolean exists(BatchLogType type);
Long create(BatchLogType type, String hostName, String status); Long create(BatchLogType type, String ip, String status);
void createError(BatchLogType type, String hostName, String status, String errorMessage); void createError(BatchLogType type, String ip, String status, String errorMessage);
void update(Long id, String hostName, String status, String errorMessage); void update(Long id, String ip, String status, String errorMessage);
} }

View File

@@ -4,7 +4,7 @@ import app.module.admin.usecase.batchLog.ports.application.domain.BatchLogType;
public interface BatchLogPortOut { public interface BatchLogPortOut {
boolean exists(BatchLogType type); boolean exists(BatchLogType type);
Long create(BatchLogType type, String hostName, String status); Long create(BatchLogType type, String ip, String status);
void createError(BatchLogType type, String hostName, String status, String errorMessage); void createError(BatchLogType type, String ip, String status, String errorMessage);
void update(Long id, String hostName, String status, String errorMessage); void update(Long id, String ip, String status, String errorMessage);
} }

View File

@@ -17,17 +17,17 @@ class BatchLogService implements BatchLogPortIn {
} }
@Override @Override
public Long create(BatchLogType type, String hostName, String status) { public Long create(BatchLogType type, String ip, String status) {
return portOut.create(type, hostName, status); return portOut.create(type, ip, status);
} }
@Override @Override
public void createError(BatchLogType type, String hostName, String status, String errorMessage) { public void createError(BatchLogType type, String ip, String status, String errorMessage) {
portOut.createError(type, hostName, status, errorMessage); portOut.createError(type, ip, status, errorMessage);
} }
@Override @Override
public void update(Long id, String hostName, String status, String errorMessage) { public void update(Long id, String ip, String status, String errorMessage) {
portOut.update(id, hostName, status, errorMessage); portOut.update(id, ip, status, errorMessage);
} }
} }

View File

@@ -15,6 +15,6 @@ public class BatchLogCmd {
private Long id; private Long id;
private String type; private String type;
private String status; private String status;
private String ip;
private LocalDateTime startAt; private LocalDateTime startAt;
private String hostName;
} }

View File

@@ -37,7 +37,7 @@ public class AutoSchedulesController {
String methodName = "fetchMonthlyStatus"; String methodName = "fetchMonthlyStatus";
if (!schedulerEnabled) { if (!schedulerEnabled) {
log.info("{} 는 local 환경에서는 실행되지 않습니다. (현재: {})", methodName, activeProfiles); log.info("[batch] {} 는 {} 환경에서는 실행되지 않습니다.", methodName, activeProfiles);
return; return;
} }
@@ -48,16 +48,16 @@ public class AutoSchedulesController {
} }
try { try {
log.info("스케줄 실행 : {} / {} / {} / {} / {}", log.info("[batch] 스케줄 실행 : {} / {} / {} / {} / {}",
methodName, java.net.InetAddress.getLocalHost().getHostName(), this, methodName, java.net.InetAddress.getLocalHost().getHostAddress(), this,
+System.identityHashCode(this), Thread.currentThread().getName()); +System.identityHashCode(this), Thread.currentThread().getName());
// 월별입력상태 실행 // 월별입력상태 실행
portIn.operate(); portIn.operate();
} catch (Exception e) { } catch (Exception e) {
log.error("예외 발생 : {} / {}", methodName, e.getMessage(), e); log.error("[batch] 예외 발생 : {} / {}", methodName, e.getMessage(), e);
} finally { } finally {
log.info("스케줄 종료 : {}", methodName); log.info("[batch] 스케줄 종료 : {}", methodName);
} }
} }
@@ -65,12 +65,12 @@ public class AutoSchedulesController {
* 문자자동발송 등록 * 문자자동발송 등록
* 매일 오후 5시 마다 실행되는 스케줄러 * 매일 오후 5시 마다 실행되는 스케줄러
*/ */
@Scheduled(cron = "0 0 18 * * ?") @Scheduled(cron = "0 0 17 * * ?")
public void fetchSmsAutoSend() { public void fetchSmsAutoSend() {
String methodName = "fetchSmsAutoSend"; String methodName = "fetchSmsAutoSend";
if (!schedulerEnabled) { if (!schedulerEnabled) {
log.info("{} 는 local 환경에서는 실행되지 않습니다. (현재: {})", methodName, activeProfiles); log.info("[batch] {} 는 {} 환경에서는 실행되지 않습니다.", methodName, activeProfiles);
return; return;
} }
@@ -81,16 +81,16 @@ public class AutoSchedulesController {
} }
try { try {
log.info("스케줄 실행 : {} / {} / {} / {} / {}", log.info("[batch] 스케줄 실행 : {} / {} / {} / {} / {}",
methodName, java.net.InetAddress.getLocalHost().getHostName(), this, methodName, java.net.InetAddress.getLocalHost().getHostAddress(), this,
+System.identityHashCode(this), Thread.currentThread().getName()); +System.identityHashCode(this), Thread.currentThread().getName());
// 문자자동발송 실행 // 문자자동발송 실행
portIn.sendAutoSms(); portIn.sendAutoSms();
} catch (Exception e) { } catch (Exception e) {
log.error("예외 발생 : {} / {}", methodName, e.getMessage(), e); log.error("[batch] 예외 발생 : {} / {}", methodName, e.getMessage(), e);
} finally { } finally {
log.info("스케줄 종료 : {}", methodName); log.info("[batch] 스케줄 종료 : {}", methodName);
} }
} }
@@ -103,7 +103,7 @@ public class AutoSchedulesController {
String methodName = "fetchMonthlyCarryOver"; String methodName = "fetchMonthlyCarryOver";
if (!schedulerEnabled) { if (!schedulerEnabled) {
log.info("{} 는 local 환경에서는 실행되지 않습니다. (현재: {})", methodName, activeProfiles); log.info("[batch] {} 는 {} 환경에서는 실행되지 않습니다.", methodName, activeProfiles);
return; return;
} }
@@ -114,16 +114,16 @@ public class AutoSchedulesController {
} }
try { try {
log.info("스케줄 실행 : {} / {} / {} / {} / {}", log.info("[batch] 스케줄 실행 : {} / {} / {} / {} / {}",
methodName, java.net.InetAddress.getLocalHost().getHostName(), this, methodName, java.net.InetAddress.getLocalHost().getHostAddress(), this,
+System.identityHashCode(this), Thread.currentThread().getName()); +System.identityHashCode(this), Thread.currentThread().getName());
// 월초이월금 실행 // 월초이월금 실행
portIn.monthlyCarryOver(); portIn.monthlyCarryOver();
} catch (Exception e) { } catch (Exception e) {
log.error("예외 발생 : {} / {}", methodName, e.getMessage(), e); log.error("[batch] 예외 발생 : {} / {}", methodName, e.getMessage(), e);
} finally { } finally {
log.info("스케줄 종료 : {}", methodName); log.info("[batch] 스케줄 종료 : {}", methodName);
} }
} }
} }

View File

@@ -2,8 +2,8 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" > <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="app.module.admin.usecase.batchCheck.adapters.persistence.BatchCheckMapper" > <mapper namespace="app.module.admin.usecase.batchCheck.adapters.persistence.BatchCheckMapper" >
<insert id="create"> <insert id="create">
/* create : 배치 실행 여부 등록 */ /* create : 배치 중복 실행 방지를 위한 등록 */
INSERT INTO batch_check(type, run_date) INSERT INTO batch_check(type, run_date, created_ip, created_at)
VALUES (#{type}, #{runDate}) VALUES (#{type}, #{runDate}, #{ip}, now())
</insert> </insert>
</mapper> </mapper>

View File

@@ -19,8 +19,8 @@
SELECT nextval('batch_log_seq') SELECT nextval('batch_log_seq')
</selectKey> </selectKey>
INSERT INTO batch_log (id, type, status, start_at, created_at, created_host) INSERT INTO batch_log (id, type, status, start_at, created_at, created_ip)
VALUES (#{id}, #{type}, #{status}, #{startAt}, now(), #{hostName}) VALUES (#{id}, #{type}, #{status}, #{startAt}, now(), #{ip})
</insert> </insert>
<!-- 에러 로그 insert --> <!-- 에러 로그 insert -->
@@ -29,8 +29,8 @@
SELECT nextval('batch_log_seq') SELECT nextval('batch_log_seq')
</selectKey> </selectKey>
INSERT INTO batch_log (id, type, status, error_message, start_at, created_at, created_host) INSERT INTO batch_log (id, type, status, error_message, start_at, created_at, created_ip)
VALUES (#{id}, #{type}, #{status}, #{errorMessage}, now(), now(), #{hostName}) VALUES (#{id}, #{type}, #{status}, #{errorMessage}, now(), now(), #{ip})
</insert> </insert>
<!-- 상태 업데이트 --> <!-- 상태 업데이트 -->
@@ -39,7 +39,7 @@
SET status = #{status}, SET status = #{status},
error_message = #{errorMessage}, error_message = #{errorMessage},
end_at = now(), end_at = now(),
created_host = #{hostName} created_ip = #{ip}
WHERE id = #{id} WHERE id = #{id}
</update> </update>
</mapper> </mapper>

View File

@@ -415,7 +415,7 @@ CREATE TABLE batch_log (
end_at TIMESTAMP, end_at TIMESTAMP,
error_message VARCHAR(2000), error_message VARCHAR(2000),
created_at TIMESTAMP DEFAULT now(), created_at TIMESTAMP DEFAULT now(),
created_host VARCHAR(100), created_ip VARCHAR(50),
CONSTRAINT batch_log_pkey PRIMARY KEY (id) CONSTRAINT batch_log_pkey PRIMARY KEY (id)
); );
@@ -427,7 +427,7 @@ COMMENT ON COLUMN batch_log.start_at IS '배치 시작 시간';
COMMENT ON COLUMN batch_log.end_at IS '배치 종료 시간'; COMMENT ON COLUMN batch_log.end_at IS '배치 종료 시간';
COMMENT ON COLUMN batch_log.error_message IS '에러 메시지 (실패한 경우)'; COMMENT ON COLUMN batch_log.error_message IS '에러 메시지 (실패한 경우)';
COMMENT ON COLUMN batch_log.created_at IS '생성일'; COMMENT ON COLUMN batch_log.created_at IS '생성일';
COMMENT ON COLUMN batch_log.created_host IS '생성HOST'; COMMENT ON COLUMN batch_log.created_ip IS '생성 IP';
@@ -435,8 +435,10 @@ COMMENT ON COLUMN batch_log.created_host IS '생성HOST';
-- 배치 실행 여부 -- 배치 실행 여부
-- ==================================================================================================================== -- ====================================================================================================================
CREATE TABLE batch_check ( CREATE TABLE batch_check (
type VARCHAR(50) NOT NULL, type VARCHAR(50) NOT NULL,
run_date DATE NOT NULL, run_date DATE NOT NULL,
created_ip VARCHAR(50) NOT NULL,
created_at TIMESTAMP DEFAULT now(),
PRIMARY KEY (type, run_date) PRIMARY KEY (type, run_date)
); );
@@ -444,6 +446,8 @@ COMMENT ON TABLE batch_check IS '배치 실행 여부 테이블';
COMMENT ON COLUMN batch_check.type IS '배치 타입'; COMMENT ON COLUMN batch_check.type IS '배치 타입';
COMMENT ON COLUMN batch_check.run_date IS '배치 실행 날짜'; COMMENT ON COLUMN batch_check.run_date IS '배치 실행 날짜';
COMMENT ON COLUMN batch_check.created_ip IS '실행 IP';
COMMENT ON COLUMN batch_check.created_at IS '생성일';