[KC-108] ai api batch 작업중
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
package com.kamco.cd.kamcoback.scheduler.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.List;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class JobStatusDto {
|
||||
|
||||
private Long id;
|
||||
|
||||
@JsonProperty("created_at")
|
||||
private ZonedDateTime createdAt;
|
||||
|
||||
@JsonProperty("input1_year")
|
||||
private Integer input1Year;
|
||||
|
||||
@JsonProperty("input2_year")
|
||||
private Integer input2Year;
|
||||
|
||||
@JsonProperty("total_jobs")
|
||||
private Integer totalJobs;
|
||||
|
||||
@JsonProperty("pending_jobs")
|
||||
private Integer pendingJobs;
|
||||
|
||||
@JsonProperty("running_jobs")
|
||||
private Integer runningJobs;
|
||||
|
||||
@JsonProperty("completed_jobs")
|
||||
private Integer completedJobs;
|
||||
|
||||
@JsonProperty("failed_jobs")
|
||||
private Integer failedJobs;
|
||||
|
||||
private String status;
|
||||
|
||||
private List<Object> jobs;
|
||||
|
||||
@JsonProperty("completed_ids")
|
||||
private List<String> completedIds;
|
||||
|
||||
@JsonProperty("processing_ids")
|
||||
private List<String> processingIds;
|
||||
|
||||
@JsonProperty("queued_ids")
|
||||
private List<String> queuedIds;
|
||||
|
||||
@JsonProperty("failed_ids")
|
||||
private List<String> failedIds;
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user