[KC-108] ai api batch 작업중

This commit is contained in:
2026-01-12 20:03:04 +09:00
parent ededc512d6
commit 9022f05cc5
13 changed files with 207 additions and 86 deletions

View File

@@ -1,8 +1,19 @@
package com.kamco.cd.kamcoback.scheduler.service;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.kamco.cd.kamcoback.config.resttemplate.ExternalHttpClient;
import com.kamco.cd.kamcoback.config.resttemplate.ExternalHttpClient.ExternalCallResult;
import com.kamco.cd.kamcoback.inference.dto.InferenceResultDto.Status;
import com.kamco.cd.kamcoback.postgres.core.InferenceResultCoreService;
import com.kamco.cd.kamcoback.scheduler.dto.JobStatusDto;
import java.util.List;
import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
@@ -12,6 +23,12 @@ import org.springframework.stereotype.Service;
public class MapSheetInferenceJobService {
private final InferenceResultCoreService inferenceResultCoreService;
private final ExternalHttpClient externalHttpClient;
private final ObjectMapper objectMapper;
@Value("${inference.batch-url}")
private String batchUrl;
@Scheduled(fixedDelay = 60_000)
public void runBatch() {
@@ -19,8 +36,36 @@ public class MapSheetInferenceJobService {
try {
// TODO: 배치 로직 작성
Long batchId =
inferenceResultCoreService.getInferenceResultByStatus(Status.IN_PROGRESS.getId());
if (batchId == null) {
return;
}
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.setAccept(List.of(MediaType.APPLICATION_JSON));
String url = batchUrl + "/" + batchId;
ExternalCallResult<String> result =
externalHttpClient.call(url, HttpMethod.GET, null, headers, String.class);
int status = result.statusCode();
if (status < 200 || status >= 300) {
return;
}
String json = result.body();
JobStatusDto dto = objectMapper.readValue(json, JobStatusDto.class);
System.out.println(dto);
Thread.sleep(3000); // 예시: 처리 시간 3초
} catch (InterruptedException e) {
} catch (InterruptedException | JsonProcessingException e) {
Thread.currentThread().interrupt();
log.error("배치 중 인터럽트 발생", e);
}