이메일 발송 테스트 코드

This commit is contained in:
Rinjae
2025-11-10 11:23:26 +09:00
parent 5b354cffb1
commit ccc4a80c99
3 changed files with 48 additions and 24 deletions
@@ -36,7 +36,6 @@ public class EmailJob {
private static final int BEFORE_SEND = 2;
private static final int SEND = 3;
private final Path tempFilePath;
private final Path eaiFilePath;
private final Path backupFilePath;
private final Path failedFilePath;
@@ -52,7 +51,6 @@ public class EmailJob {
this.prop = prop;
String filename = messageRequest.getServiceId() + "_" + DateTimeFormatter.ofPattern("yyyyMMddHHmmss").format(now);
this.tempFilePath = Paths.get(prop.getUmsEaiBatchSendDir(), filename + ".tmp");
this.eaiFilePath = Paths.get(prop.getUmsEaiBatchSendDir(), filename);
this.backupFilePath = Paths.get(prop.getUmsEaiBatchBackupDir(), filename);
this.failedFilePath = Paths.get(prop.getUmsEaiBatchBackupDir(), filename + ".failed");
@@ -192,7 +190,7 @@ public class EmailJob {
throw new IllegalStateException("Mail File exists for ID: " + messageRequest.getId());
}
File mailFile = tempFilePath.toFile();
File mailFile = eaiFilePath.toFile();
try {
boolean created = mailFile.createNewFile();
if (!created) {
@@ -218,22 +216,11 @@ public class EmailJob {
throw new RuntimeException(e);
}
try {
Files.write(tempFilePath, data);
Files.copy(tempFilePath, eaiFilePath);
Files.delete(tempFilePath);
Files.write(eaiFilePath, data);
log.debug("Wrote JSON to file: {}", eaiFilePath.toString());
} catch (IOException e) {
log.error("Cannot write JSON to file: {}", eaiFilePath.toString(), e);
throw new RuntimeException(e);
} finally {
// 임시 파일이 남아 있다면 오류 상황이므로 에러 경로로 이동
if (Files.exists(tempFilePath)) {
try {
Files.move(tempFilePath, Paths.get(prop.getUmsEaiBatchErrorDir(), tempFilePath.getFileName().toString()));
} catch (IOException e) {
log.warn("임시 파일 저장시 실패 하여 에러 경로로 옮기는 도중 에러 발생", e);
}
}
}
}