[KC-103] 추론 실행 배치 수정

This commit is contained in:
2026-01-13 15:51:33 +09:00
parent 65bac54db5
commit 8b212504d4
5 changed files with 54 additions and 34 deletions

View File

@@ -96,7 +96,7 @@ public class InferenceResultService {
// 기준년도 조회
List<MngListDto> targetList = mapSheetMngCoreService.getHstMapSheetList(req.getTargetYyyy());
req.setMapSheetNum(this.createdMngDto(req, targetList));
req.setMapSheetNum(createdMngDto(req, targetList));
} else {
// 부분
@@ -107,7 +107,7 @@ public class InferenceResultService {
// 기준년도 조회
List<MngListDto> targetList =
mapSheetMngCoreService.getHstMapSheetList(req.getTargetYyyy(), mapTargetIds);
req.setMapSheetNum(this.createdMngDto(req, targetList));
req.setMapSheetNum(createdMngDto(req, targetList));
}
if (req.getMapSheetNum().isEmpty()) {
@@ -116,7 +116,9 @@ public class InferenceResultService {
// 추론 테이블 저장
UUID uuid = inferenceResultCoreService.saveInferenceInfo(req);
this.startInference(req, uuid);
// 추론 실행 API 호출
startInference(req, uuid);
return uuid;
}
@@ -198,9 +200,9 @@ public class InferenceResultService {
}
String modelComparePath =
this.getSceneInference(String.valueOf(req.getCompareYyyy()), mapSheetNumList);
getSceneInference(String.valueOf(req.getCompareYyyy()), mapSheetNumList);
String modelTargetPath =
this.getSceneInference(String.valueOf(req.getTargetYyyy()), mapSheetNumList);
getSceneInference(String.valueOf(req.getTargetYyyy()), mapSheetNumList);
pred_requests_areas predRequestsAreas = new pred_requests_areas();
predRequestsAreas.setInput1_year(req.getCompareYyyy());

View File

@@ -104,13 +104,13 @@ public class InferenceResultCoreService {
buffer.add(e);
if (buffer.size() == CHUNK) {
this.flushChunk(buffer);
flushChunk(buffer);
buffer.clear();
}
}
if (!buffer.isEmpty()) {
this.flushChunk(buffer);
flushChunk(buffer);
buffer.clear();
}

View File

@@ -144,8 +144,9 @@ public class MapSheetLearnRepositoryImpl implements MapSheetLearnRepositoryCusto
return Optional.ofNullable(
queryFactory
.selectFrom(mapSheetLearnEntity)
.where(mapSheetLearnEntity.status.eq(status))
.limit(1)
.where(mapSheetLearnEntity.id.eq(106L))
// .where(mapSheetLearnEntity.status.eq(status))
// .limit(1)
.fetchOne());
}

View File

@@ -3,6 +3,7 @@ package com.kamco.cd.kamcoback.scheduler;
import com.kamco.cd.kamcoback.code.dto.CommonCodeDto;
import com.kamco.cd.kamcoback.code.service.CommonCodeService;
import com.kamco.cd.kamcoback.config.api.ApiResponseDto;
import com.kamco.cd.kamcoback.scheduler.service.MapSheetInferenceJobService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
@@ -10,6 +11,7 @@ import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
@@ -23,6 +25,7 @@ public class MapSheetMngFileJobApiController {
private final CommonCodeService commonCodeService;
private final MapSheetMngFileJobController mapSheetMngFileJobController;
private final MapSheetInferenceJobService mapSheetInferenceJobService;
@Operation(summary = "영상관리 파일 싱크 스캐쥴러 Start/Stop", description = "영상관리 파일 싱크 스캐쥴러 Start/Stop API")
@ApiResponses(
@@ -46,4 +49,22 @@ public class MapSheetMngFileJobApiController {
return ApiResponseDto.createOK("OK");
}
@GetMapping("/inference-batch")
@ApiResponses(
value = {
@ApiResponse(
responseCode = "200",
description = "실행 성공",
content =
@Content(
mediaType = "application/json",
schema = @Schema(implementation = String.class))),
@ApiResponse(responseCode = "404", description = "코드를 찾을 수 없음", content = @Content),
@ApiResponse(responseCode = "500", description = "서버 오류", content = @Content)
})
public ApiResponseDto<String> inferenceRunBatch() {
mapSheetInferenceJobService.runBatch();
return ApiResponseDto.createOK("OK");
}
}

View File

@@ -26,7 +26,6 @@ import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
@Log4j2
@@ -48,15 +47,13 @@ public class MapSheetInferenceJobService {
@Value("${inference.url}")
private String inferenceUrl;
/**
* 추론 진행 배치 1분
*/
@Scheduled(fixedDelay = 60_000)
/** 추론 진행 배치 1분 */
// @Scheduled(fixedDelay = 60_000)
@Transactional
public void runBatch() {
if ("local".equalsIgnoreCase(profile)) {
return;
// return;
}
try {
@@ -103,23 +100,23 @@ public class MapSheetInferenceJobService {
int failedJobs = dto.getFailedJobs();
// 성공, 실패 값 더해서 total 과 같으면 완료
String inferStatus = this.setStatus(totalJobs, completedJobs, failedJobs);
String inferStatus = setStatus(totalJobs, completedJobs, failedJobs);
if ("COMPLETED".equals(inferStatus)) {
String type = batchSheet.getRunningModelType();
if (type.equals("M1")) {
// M1 완료되었으면 M2 실행
this.startInference(
startInference(
batchSheet.getId(), batchSheet.getUuid(), "M2", batchSheet.getM2ModelUuid());
// 종료시간
this.updateProcessingEndTimeByModel(batchSheet.getUuid(), ZonedDateTime.now(), "M1");
updateProcessingEndTimeByModel(batchSheet.getUuid(), ZonedDateTime.now(), "M1");
} else if (type.equals("M2")) {
// M2 완료되었으면 M3 실행
this.startInference(
startInference(
batchSheet.getId(), batchSheet.getUuid(), "M3", batchSheet.getM3ModelUuid());
// 종료시간
this.updateProcessingEndTimeByModel(batchSheet.getUuid(), ZonedDateTime.now(), "M2");
updateProcessingEndTimeByModel(batchSheet.getUuid(), ZonedDateTime.now(), "M2");
} else if (type.equals("M3")) {
// 완료
SaveInferenceAiDto saveInferenceAiDto = new SaveInferenceAiDto();
@@ -129,7 +126,7 @@ public class MapSheetInferenceJobService {
saveInferenceAiDto.setType(type);
inferenceResultCoreService.update(saveInferenceAiDto);
// 종료시간
this.updateProcessingEndTimeByModel(batchSheet.getUuid(), ZonedDateTime.now(), "M3");
updateProcessingEndTimeByModel(batchSheet.getUuid(), ZonedDateTime.now(), "M3");
}
} else {
SaveInferenceAiDto saveInferenceAiDto = new SaveInferenceAiDto();
@@ -181,7 +178,7 @@ public class MapSheetInferenceJobService {
m.setPriority(progressDto.getPriority());
// 추론 다음모델 실행
Long batchId = this.ensureAccepted(m);
Long batchId = ensureAccepted(m);
SaveInferenceAiDto saveInferenceAiDto = new SaveInferenceAiDto();
saveInferenceAiDto.setUuid(uuid);
@@ -230,8 +227,7 @@ public class MapSheetInferenceJobService {
try {
List<Map<String, Object>> list =
om.readValue(body, new TypeReference<List<Map<String, Object>>>() {
});
om.readValue(body, new TypeReference<List<Map<String, Object>>>() {});
Integer batchIdInt = (Integer) list.get(0).get("batch_id");
batchId = batchIdInt.longValue();