261023_01_ENH: 비동기 메시지 발송 부분 성공 상태 추가 및 수신처 없는 대상 건너뛰기
This commit is contained in:
@@ -3,11 +3,11 @@ package com.kri.contact.server.common.enums;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public enum ListAsyncJobStatus {
|
public enum ListAsyncJobStatus {
|
||||||
QUEUED, RUNNING, CANCEL_REQUESTED, CANCELLED, SUCCEEDED, FAILED;
|
QUEUED, RUNNING, CANCEL_REQUESTED, CANCELLED, SUCCEEDED, FAILED, PARTIALLY_SUCCEEDED;
|
||||||
|
|
||||||
public static final List<ListAsyncJobStatus> ACTIVE = List.of(QUEUED, RUNNING, CANCEL_REQUESTED);
|
public static final List<ListAsyncJobStatus> ACTIVE = List.of(QUEUED, RUNNING, CANCEL_REQUESTED);
|
||||||
|
|
||||||
public boolean isTerminal() {
|
public boolean isTerminal() {
|
||||||
return this == CANCELLED || this == SUCCEEDED || this == FAILED;
|
return this == CANCELLED || this == SUCCEEDED || this == FAILED || this == PARTIALLY_SUCCEEDED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -179,6 +179,9 @@ public class ListAsyncJobExecutor implements ApplicationRunner {
|
|||||||
public void complete(Runnable changes) {
|
public void complete(Runnable changes) {
|
||||||
store.complete(task.key, changes, this::checkCancelled);
|
store.complete(task.key, changes, this::checkCancelled);
|
||||||
}
|
}
|
||||||
|
public void completePartially(String code, String message, Map<String, Object> detail) {
|
||||||
|
store.completePartially(task.key, code, message, detail, this::checkCancelled);
|
||||||
|
}
|
||||||
public void reject(String code, String message, Map<String, Object> detail) {
|
public void reject(String code, String message, Map<String, Object> detail) {
|
||||||
checkCancelled();
|
checkCancelled();
|
||||||
store.reject(task.key, code, message, detail);
|
store.reject(task.key, code, message, detail);
|
||||||
|
|||||||
@@ -100,6 +100,21 @@ public class ListAsyncJobStore {
|
|||||||
BusinessException.notFound("LIST_JOB_NOT_FOUND", "작업을 찾을 수 없습니다."));
|
BusinessException.notFound("LIST_JOB_NOT_FOUND", "작업을 찾을 수 없습니다."));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transactional(propagation = Propagation.REQUIRES_NEW)
|
||||||
|
public void completePartially(String key, String code, String message, Map<String, Object> detail,
|
||||||
|
Runnable checkCancelled) {
|
||||||
|
var job = lock(key);
|
||||||
|
requireRunning(job);
|
||||||
|
checkCancelled.run();
|
||||||
|
job.setErrorDetailJson(detail);
|
||||||
|
job.setJobStatus(ListAsyncJobStatus.PARTIALLY_SUCCEEDED);
|
||||||
|
job.setJobStage("COMPLETED");
|
||||||
|
job.setErrorCode(code);
|
||||||
|
job.setErrorMessage(message);
|
||||||
|
job.setFinishedDt(DateTimeUtil.nowKstLocalDateTime());
|
||||||
|
job.setModDt(job.getFinishedDt());
|
||||||
|
}
|
||||||
|
|
||||||
@Transactional(readOnly = true, propagation = Propagation.REQUIRES_NEW)
|
@Transactional(readOnly = true, propagation = Propagation.REQUIRES_NEW)
|
||||||
public List<ListAsyncJobActivity> activity(
|
public List<ListAsyncJobActivity> activity(
|
||||||
Long projectId, List<String> heldKeys) {
|
Long projectId, List<String> heldKeys) {
|
||||||
@@ -114,7 +129,8 @@ public class ListAsyncJobStore {
|
|||||||
return jobs.summarizeFinishedMutations(projectId,
|
return jobs.summarizeFinishedMutations(projectId,
|
||||||
List.of(ListAsyncJobType.LIST_UPLOAD, ListAsyncJobType.LIST_RESET,
|
List.of(ListAsyncJobType.LIST_UPLOAD, ListAsyncJobType.LIST_RESET,
|
||||||
ListAsyncJobType.LIST_UPDATE, ListAsyncJobType.LIST_ASSIGN),
|
ListAsyncJobType.LIST_UPDATE, ListAsyncJobType.LIST_ASSIGN),
|
||||||
List.of(ListAsyncJobStatus.SUCCEEDED, ListAsyncJobStatus.FAILED, ListAsyncJobStatus.CANCELLED),
|
List.of(ListAsyncJobStatus.SUCCEEDED, ListAsyncJobStatus.PARTIALLY_SUCCEEDED,
|
||||||
|
ListAsyncJobStatus.FAILED, ListAsyncJobStatus.CANCELLED),
|
||||||
heldKeys.isEmpty() ? List.of("") : heldKeys);
|
heldKeys.isEmpty() ? List.of("") : heldKeys);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -61,6 +61,7 @@ public class ListAsyncMessageService {
|
|||||||
var failedSids = new HashSet<String>();
|
var failedSids = new HashSet<String>();
|
||||||
var keys = new HashSet<String>();
|
var keys = new HashSet<String>();
|
||||||
int duplicates = 0;
|
int duplicates = 0;
|
||||||
|
int noDestinationSkippedSids = 0;
|
||||||
try (var prepared = spool.open(context.jobKey())) {
|
try (var prepared = spool.open(context.jobKey())) {
|
||||||
var buffer = new ArrayList<NotiHubDestInfoDto>();
|
var buffer = new ArrayList<NotiHubDestInfoDto>();
|
||||||
for (int offset = 0; offset < frozen.size(); offset += 1000) {
|
for (int offset = 0; offset < frozen.size(); offset += 1000) {
|
||||||
@@ -90,6 +91,10 @@ public class ListAsyncMessageService {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (candidates.isEmpty()) {
|
if (candidates.isEmpty()) {
|
||||||
|
boolean noDestination = request.destHeaderIds().stream()
|
||||||
|
.map(row.itemMap()::get)
|
||||||
|
.allMatch(value -> value == null || value.trim().isEmpty());
|
||||||
|
if (noDestination) { noDestinationSkippedSids++; continue; }
|
||||||
failures.add(Map.of("code", "NO_DESTINATION", "sids", List.of(row.sid())));
|
failures.add(Map.of("code", "NO_DESTINATION", "sids", List.of(row.sid())));
|
||||||
failedSids.add(row.sid());
|
failedSids.add(row.sid());
|
||||||
}
|
}
|
||||||
@@ -113,6 +118,7 @@ public class ListAsyncMessageService {
|
|||||||
progress.put("targetSidCnt", frozen.size());
|
progress.put("targetSidCnt", frozen.size());
|
||||||
progress.put("preparedRecipientCnt", prepared.targets());
|
progress.put("preparedRecipientCnt", prepared.targets());
|
||||||
progress.put("preparationFailedSidCnt", failedSids.size());
|
progress.put("preparationFailedSidCnt", failedSids.size());
|
||||||
|
progress.put("noDestinationSkippedSidCnt", noDestinationSkippedSids);
|
||||||
progress.put("duplicateSkippedRecipientCnt", duplicates);
|
progress.put("duplicateSkippedRecipientCnt", duplicates);
|
||||||
for (String metric : List.of("acceptedRecipientCnt", "failedRecipientCnt", "unknownRecipientCnt",
|
for (String metric : List.of("acceptedRecipientCnt", "failedRecipientCnt", "unknownRecipientCnt",
|
||||||
"attemptedRecipientCnt", "processedRecipientCnt", "inFlightRecipientCnt")) progress.put(metric, 0L);
|
"attemptedRecipientCnt", "processedRecipientCnt", "inFlightRecipientCnt")) progress.put(metric, 0L);
|
||||||
@@ -145,6 +151,7 @@ public class ListAsyncMessageService {
|
|||||||
progress.put("bulkSendKey", bulkKey);
|
progress.put("bulkSendKey", bulkKey);
|
||||||
context.progress("DISPATCHING", null, progress);
|
context.progress("DISPATCHING", null, progress);
|
||||||
long failed = failedSids.size();
|
long failed = failedSids.size();
|
||||||
|
long accepted = 0;
|
||||||
for (int number = 1; number <= prepared.batches(); number++) {
|
for (int number = 1; number <= prepared.batches(); number++) {
|
||||||
context.checkCancelled();
|
context.checkCancelled();
|
||||||
access.requireProject(projectId, user);
|
access.requireProject(projectId, user);
|
||||||
@@ -168,12 +175,16 @@ public class ListAsyncMessageService {
|
|||||||
}
|
}
|
||||||
// Persist the observed outcome even if cancellation arrived during the HTTP call.
|
// Persist the observed outcome even if cancellation arrived during the HTTP call.
|
||||||
context.messageBatch(number, result);
|
context.messageBatch(number, result);
|
||||||
|
accepted += ((Number) result.get("acceptedRecipientCnt")).longValue();
|
||||||
failed += ((Number) result.get("failedRecipientCnt")).longValue() + ((Number) result.get("unknownRecipientCnt")).longValue();
|
failed += ((Number) result.get("failedRecipientCnt")).longValue() + ((Number) result.get("unknownRecipientCnt")).longValue();
|
||||||
}
|
}
|
||||||
prepared.close();
|
prepared.close();
|
||||||
finishCycle(context);
|
finishCycle(context);
|
||||||
if (failed > 0) context.reject("MESSAGE_PARTIAL_FAILURE", "전체 대상 처리를 마쳤으며 실패 또는 접수 불명 대상이 있습니다.", context.job().getErrorDetailJson());
|
if (failed == 0) context.complete(() -> {});
|
||||||
else context.complete(() -> {});
|
else if (accepted > 0) context.completePartially("MESSAGE_PARTIAL_FAILURE",
|
||||||
|
"일부 수신처가 접수되었으며 실패 또는 접수 불명 대상이 있습니다.", context.job().getErrorDetailJson());
|
||||||
|
else context.reject("MESSAGE_SEND_FAILED", "접수 성공이 확인된 수신처가 없습니다. 실패 또는 접수 불명 내역을 확인해 주세요.",
|
||||||
|
context.job().getErrorDetailJson());
|
||||||
} catch (IOException failure) {
|
} catch (IOException failure) {
|
||||||
var wrapped = BusinessException.internalError("MESSAGE_PREPARATION_FAILED", "발송 준비 파일 처리에 실패했습니다.");
|
var wrapped = BusinessException.internalError("MESSAGE_PREPARATION_FAILED", "발송 준비 파일 처리에 실패했습니다.");
|
||||||
wrapped.addSuppressed(failure);
|
wrapped.addSuppressed(failure);
|
||||||
|
|||||||
Reference in New Issue
Block a user