[KC-103] 추론 실행 배치 수정
This commit is contained in:
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,20 +47,18 @@ 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 {
|
||||
InferenceBatchSheet batchSheet =
|
||||
inferenceResultCoreService.getInferenceResultByStatus(Status.IN_PROGRESS.getId());
|
||||
inferenceResultCoreService.getInferenceResultByStatus(Status.IN_PROGRESS.getId());
|
||||
|
||||
if (batchSheet == null) {
|
||||
return;
|
||||
@@ -88,7 +85,7 @@ public class MapSheetInferenceJobService {
|
||||
String url = batchUrl + "/" + batchId;
|
||||
|
||||
ExternalCallResult<String> result =
|
||||
externalHttpClient.call(url, HttpMethod.GET, null, headers, String.class);
|
||||
externalHttpClient.call(url, HttpMethod.GET, null, headers, String.class);
|
||||
|
||||
int status = result.statusCode();
|
||||
if (status < 200 || status >= 300) {
|
||||
@@ -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(
|
||||
batchSheet.getId(), batchSheet.getUuid(), "M2", batchSheet.getM2ModelUuid());
|
||||
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(
|
||||
batchSheet.getId(), batchSheet.getUuid(), "M3", batchSheet.getM3ModelUuid());
|
||||
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();
|
||||
@@ -148,7 +145,7 @@ public class MapSheetInferenceJobService {
|
||||
private void startInference(Long id, UUID uuid, String type, UUID modelUuid) {
|
||||
|
||||
InferenceProgressDto progressDto =
|
||||
inferenceResultCoreService.getInferenceAiResultById(id, type, modelUuid);
|
||||
inferenceResultCoreService.getInferenceAiResultById(id, type, modelUuid);
|
||||
|
||||
String inferenceType = "";
|
||||
|
||||
@@ -164,24 +161,24 @@ public class MapSheetInferenceJobService {
|
||||
predRequestsAreas.setInput1_year(progressDto.getPred_requests_areas().getInput1_year());
|
||||
predRequestsAreas.setInput2_year(progressDto.getPred_requests_areas().getInput2_year());
|
||||
predRequestsAreas.setInput1_scene_path(
|
||||
progressDto.getPred_requests_areas().getInput1_scene_path());
|
||||
progressDto.getPred_requests_areas().getInput1_scene_path());
|
||||
predRequestsAreas.setInput2_scene_path(
|
||||
progressDto.getPred_requests_areas().getInput2_scene_path());
|
||||
progressDto.getPred_requests_areas().getInput2_scene_path());
|
||||
|
||||
InferenceSendDto m = new InferenceSendDto();
|
||||
m.setPred_requests_areas(predRequestsAreas);
|
||||
m.setModel_version(progressDto.getModelVersion());
|
||||
m.setCd_model_path(progressDto.getCdModelPath() + "/" + progressDto.getCdModelFileName());
|
||||
m.setCd_model_config(
|
||||
progressDto.getCdModelConfigPath() + "/" + progressDto.getCdModelConfigFileName());
|
||||
progressDto.getCdModelConfigPath() + "/" + progressDto.getCdModelConfigFileName());
|
||||
m.setCls_model_path(
|
||||
progressDto.getCdModelClsPath() + "/" + progressDto.getCdModelClsFileName());
|
||||
progressDto.getCdModelClsPath() + "/" + progressDto.getCdModelClsFileName());
|
||||
m.setCls_model_version(progressDto.getClsModelVersion());
|
||||
m.setCd_model_type(inferenceType);
|
||||
m.setPriority(progressDto.getPriority());
|
||||
|
||||
// 추론 다음모델 실행
|
||||
Long batchId = this.ensureAccepted(m);
|
||||
Long batchId = ensureAccepted(m);
|
||||
|
||||
SaveInferenceAiDto saveInferenceAiDto = new SaveInferenceAiDto();
|
||||
saveInferenceAiDto.setUuid(uuid);
|
||||
@@ -217,7 +214,7 @@ public class MapSheetInferenceJobService {
|
||||
}
|
||||
|
||||
ExternalCallResult<String> result =
|
||||
externalHttpClient.call(inferenceUrl, HttpMethod.POST, dto, headers, String.class);
|
||||
externalHttpClient.call(inferenceUrl, HttpMethod.POST, dto, headers, String.class);
|
||||
|
||||
int status = result.statusCode();
|
||||
String body = result.body();
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user