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

배치 로그 insert, update 시 hostName추가

See merge request korea-research/korea-research!134
This commit is contained in:
이강선 매니저/ST
2025-07-21 01:58:05 +00:00
8 changed files with 32 additions and 19 deletions

View File

@@ -3,12 +3,15 @@ package app.module.admin.config.application.batch;
import app.module.admin.usecase.batchLog.ports.BatchLogPortIn;
import app.module.admin.usecase.batchLog.ports.application.domain.BatchLogType;
import app.module.core.config.application.logging.SafeLogger;
import java.net.UnknownHostException;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
@Component
@RequiredArgsConstructor
@Slf4j
public class BatchLogRunner {
SafeLogger safeLogger = new SafeLogger(LoggerFactory.getLogger(BatchLogRunner.class));
@@ -21,16 +24,24 @@ public class BatchLogRunner {
return;
}
String hostName;
try {
hostName = java.net.InetAddress.getLocalHost().getHostName();
} catch (UnknownHostException e) {
hostName = "UNKNOWN";
log.warn("호스트 이름 조회 실패", e);
}
// 실행 로그 insert (RUNNING)
Long logId = batchLogPortIn.create(batchType);
Long logId = batchLogPortIn.create(batchType, hostName);
try {
action.run();
// 성공 처리
batchLogPortIn.update(logId, "SUCCESS", null);
batchLogPortIn.update(logId, hostName,"SUCCESS", null);
} catch (Exception e) {
// 실패 처리
batchLogPortIn.update(logId, "FAIL", e.getMessage());
batchLogPortIn.update(logId, hostName,"FAIL", e.getMessage());
safeLogger.error("[{}] 배치 실패: {}", batchType.name(), e.getMessage(), e);
}
}

View File

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

View File

@@ -8,5 +8,5 @@ public interface BatchLogMapper {
boolean exists(String type);
Long create(BatchLogCmd cmd);
Long createError(String type, String hostName, String status, String errorMessage);
void update(Long id, String status, String errorMessage);
void update(Long id, String hostName, String status, String errorMessage);
}

View File

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

View File

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

View File

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

View File

@@ -16,4 +16,5 @@ public class BatchLogCmd {
private String type;
private String status;
private LocalDateTime startAt;
private String hostName;
}

View File

@@ -19,8 +19,8 @@
SELECT nextval('batch_log_seq')
</selectKey>
INSERT INTO batch_log (id, type, status, start_at, created_at)
VALUES (#{id}, #{type}, #{status}, #{startAt}, now())
INSERT INTO batch_log (id, type, status, start_at, created_at, created_host)
VALUES (#{id}, #{type}, #{status}, #{startAt}, now(), #{hostName})
</insert>
<!-- 에러 로그 insert -->
@@ -38,7 +38,8 @@
UPDATE batch_log
SET status = #{status},
error_message = #{errorMessage},
end_at = now()
end_at = now(),
created_host = #{hostName}
WHERE id = #{id}
</update>
</mapper>