배치 로그 insert, update 시 hostName추가
This commit is contained in:
@@ -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.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.UnknownHostException;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
|
@Slf4j
|
||||||
public class BatchLogRunner {
|
public class BatchLogRunner {
|
||||||
SafeLogger safeLogger = new SafeLogger(LoggerFactory.getLogger(BatchLogRunner.class));
|
SafeLogger safeLogger = new SafeLogger(LoggerFactory.getLogger(BatchLogRunner.class));
|
||||||
|
|
||||||
@@ -21,16 +24,24 @@ public class BatchLogRunner {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String hostName;
|
||||||
|
try {
|
||||||
|
hostName = java.net.InetAddress.getLocalHost().getHostName();
|
||||||
|
} catch (UnknownHostException e) {
|
||||||
|
hostName = "UNKNOWN";
|
||||||
|
log.warn("호스트 이름 조회 실패", e);
|
||||||
|
}
|
||||||
|
|
||||||
// 실행 로그 insert (RUNNING)
|
// 실행 로그 insert (RUNNING)
|
||||||
Long logId = batchLogPortIn.create(batchType);
|
Long logId = batchLogPortIn.create(batchType, hostName);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
action.run();
|
action.run();
|
||||||
// 성공 처리
|
// 성공 처리
|
||||||
batchLogPortIn.update(logId, "SUCCESS", null);
|
batchLogPortIn.update(logId, hostName,"SUCCESS", null);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// 실패 처리
|
// 실패 처리
|
||||||
batchLogPortIn.update(logId, "FAIL", e.getMessage());
|
batchLogPortIn.update(logId, hostName,"FAIL", e.getMessage());
|
||||||
safeLogger.error("[{}] 배치 실패: {}", batchType.name(), e.getMessage(), e);
|
safeLogger.error("[{}] 배치 실패: {}", batchType.name(), e.getMessage(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,8 +19,8 @@ class BatchLogDao implements BatchLogPortOut {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Long create(BatchLogType type) {
|
public Long create(BatchLogType type, String hostName) {
|
||||||
BatchLogCmd cmd = new BatchLogCmd(null, type.name(), "RUNNING", LocalDateTime.now());
|
BatchLogCmd cmd = new BatchLogCmd(null, type.name(), "RUNNING", LocalDateTime.now(), hostName);
|
||||||
mapper.create(cmd);
|
mapper.create(cmd);
|
||||||
return cmd.getId();
|
return cmd.getId();
|
||||||
}
|
}
|
||||||
@@ -31,7 +31,7 @@ class BatchLogDao implements BatchLogPortOut {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(Long id, String status, String errorMessage) {
|
public void update(Long id, String hostName, String status, String errorMessage) {
|
||||||
mapper.update(id, status, errorMessage);
|
mapper.update(id, hostName, status, errorMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -8,5 +8,5 @@ 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 hostName, String status, String errorMessage);
|
||||||
void update(Long id, String status, String errorMessage);
|
void update(Long id, String hostName, String status, String errorMessage);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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);
|
Long create(BatchLogType type, String hostName);
|
||||||
void createError(BatchLogType type, String hostName, String status, String errorMessage);
|
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);
|
||||||
}
|
}
|
||||||
@@ -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);
|
Long create(BatchLogType type, String hostName);
|
||||||
void createError(BatchLogType type, String hostName, String status, String errorMessage);
|
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);
|
||||||
}
|
}
|
||||||
@@ -17,8 +17,8 @@ class BatchLogService implements BatchLogPortIn {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Long create(BatchLogType type) {
|
public Long create(BatchLogType type, String hostName) {
|
||||||
return portOut.create(type);
|
return portOut.create(type, hostName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -27,7 +27,7 @@ class BatchLogService implements BatchLogPortIn {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(Long id, String status, String errorMessage) {
|
public void update(Long id, String hostName, String status, String errorMessage) {
|
||||||
portOut.update(id, status, errorMessage);
|
portOut.update(id, hostName, status, errorMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -16,4 +16,5 @@ public class BatchLogCmd {
|
|||||||
private String type;
|
private String type;
|
||||||
private String status;
|
private String status;
|
||||||
private LocalDateTime startAt;
|
private LocalDateTime startAt;
|
||||||
|
private String hostName;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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)
|
INSERT INTO batch_log (id, type, status, start_at, created_at, created_host)
|
||||||
VALUES (#{id}, #{type}, #{status}, #{startAt}, now())
|
VALUES (#{id}, #{type}, #{status}, #{startAt}, now(), #{hostName})
|
||||||
</insert>
|
</insert>
|
||||||
|
|
||||||
<!-- 에러 로그 insert -->
|
<!-- 에러 로그 insert -->
|
||||||
@@ -38,7 +38,8 @@
|
|||||||
UPDATE batch_log
|
UPDATE batch_log
|
||||||
SET status = #{status},
|
SET status = #{status},
|
||||||
error_message = #{errorMessage},
|
error_message = #{errorMessage},
|
||||||
end_at = now()
|
end_at = now(),
|
||||||
|
created_host = #{hostName}
|
||||||
WHERE id = #{id}
|
WHERE id = #{id}
|
||||||
</update>
|
</update>
|
||||||
</mapper>
|
</mapper>
|
||||||
Reference in New Issue
Block a user