develop #38

Merged
gitadmin merged 12 commits from develop into master 2026-10-26 08:33:11 +09:00
2 changed files with 56 additions and 3 deletions
Showing only changes of commit 8f9dda7be1 - Show all commits

View File

@@ -11,6 +11,11 @@ import com.kri.contact.server.dto.list.async.ListAsyncResultFileDto;
import com.kri.contact.server.persistence.entity.TListAsyncJobEntity;
import com.kri.contact.server.service.file.ListAsyncResultFileService;
import jakarta.annotation.PreDestroy;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.IdentityHashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
@@ -226,6 +231,32 @@ public class ListAsyncJobExecutor implements ApplicationRunner {
}
}
private static Map<String, Object> failureDetails(Throwable failure) {
var causes = new ArrayList<Map<String, Object>>();
var seen = Collections.newSetFromMap(new IdentityHashMap<Throwable, Boolean>());
Throwable current = failure;
while (current != null && causes.size() < 8 && seen.add(current)) {
var detail = new LinkedHashMap<String, Object>();
detail.put("exceptionType", current.getClass().getName());
if (current instanceof BusinessException business) {
String code = business.getCode();
if (code != null && code.matches("[A-Z][A-Z0-9_]{0,127}")) {
detail.put("businessCode", code);
}
if (business.getStatus() != null) {
detail.put("httpStatus", business.getStatus().value());
}
}
// Messages, extras and Throwable.toString() can contain uploaded data or server paths.
detail.put("stackTrace", Arrays.stream(current.getStackTrace()).limit(80)
.map(frame -> frame.getClassName() + "." + frame.getMethodName() + ":" + frame.getLineNumber())
.toList());
causes.add(detail);
current = current.getCause();
}
return Map.of("causes", causes, "truncated", current != null);
}
private final class JobTask implements Runnable {
private final String key;
private final Consumer<JobContext> work;
@@ -243,6 +274,7 @@ public class ListAsyncJobExecutor implements ApplicationRunner {
@Override
public void run() {
String errorCode = null;
Map<String, Object> failureDetail = null;
try {
if (store.start(key)) {
JobContext context = new JobContext(this);
@@ -253,8 +285,9 @@ public class ListAsyncJobExecutor implements ApplicationRunner {
// 사용자 취소는 CANCEL_REQUESTED 기록과 함께 종료한다.
cancelled.set(true);
} catch (Throwable failure) {
// 업로드 내용·전화번호·서버 경로 등이 예외 메시지에 포함될 수 있어 출력하지 않는다.
log.warn("List async job failed: jobKey={}, type={}", key, failure.getClass().getSimpleName());
failureDetail = failureDetails(failure);
log.warn("List async job failed: jobKey={}, failedChunkNo={}, detail={}",
key, failedChunkNo, failureDetail);
errorCode = "JOB_EXECUTION_FAILED";
} finally {
try {
@@ -263,7 +296,11 @@ public class ListAsyncJobExecutor implements ApplicationRunner {
} else if (cancelled.get()) {
store.requestCancel(key, cancelUser);
}
store.finish(key, errorCode, failedChunkNo);
store.finish(key, errorCode, failedChunkNo, failureDetail);
} catch (RuntimeException | Error finishFailure) {
log.error("List async job finalization failed: jobKey={}, detail={}",
key, failureDetails(finishFailure));
throw finishFailure;
} finally {
tasks.remove(key, this);
release();

View File

@@ -180,6 +180,22 @@ public class ListAsyncJobStore {
finishLocked(lock(key), errorCode, failedChunkNo);
}
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void finish(String key, String errorCode, Integer failedChunkNo,
Map<String, Object> failureDetail) {
var job = lock(key);
if (!job.getJobStatus().isTerminal() && failureDetail != null) {
var detail = new java.util.LinkedHashMap<String, Object>(
job.getErrorDetailJson() == null ? Map.of() : job.getErrorDetailJson());
var executionFailure = new java.util.LinkedHashMap<String, Object>(failureDetail);
executionFailure.put("stage", job.getJobStage());
executionFailure.put("failedChunkNo", failedChunkNo);
detail.put("executionFailure", executionFailure);
job.setErrorDetailJson(detail);
}
finishLocked(job, errorCode, failedChunkNo);
}
private void finishLocked(TListAsyncJobEntity job, String errorCode, Integer failedChunkNo) {
if (job.getJobStatus().isTerminal()) {
return;