[수정] KubeflowRunResponse 필드 명칭 표준화 및 배치 구성의 runReader 로직 업데이트: 페이지네이션과 정렬 로직 간소화

main
bjkim 9 months ago
parent 1224f88a71
commit c134b6a361

@ -22,6 +22,7 @@ import org.springframework.web.reactive.function.client.WebClient;
import java.time.Instant; import java.time.Instant;
import java.util.List; import java.util.List;
import java.util.Optional;
@Configuration @Configuration
@EnableBatchProcessing @EnableBatchProcessing
@ -33,7 +34,9 @@ public class KubeflowRunBatchConfig {
private final KubeflowRunRepository kubeflowRunRepository; private final KubeflowRunRepository kubeflowRunRepository;
// 최신 데이터 몇 개만 가져올지 // 최신 데이터 몇 개만 가져올지
private static final int PAGE_SIZE = 50; private static final int PAGE_SIZE = 10;
private static final String SORT_BY = "created_at DESC";
@Bean @Bean
public WebClient.Builder webClientBuilder() { public WebClient.Builder webClientBuilder() {
@ -65,35 +68,39 @@ public class KubeflowRunBatchConfig {
@Bean @Bean
public ItemReader<KubeflowRunRequest> runReader() { public ItemReader<KubeflowRunRequest> runReader() {
return new ItemReader<>() { return new ItemReader<>() {
private boolean read = false; private List<KubeflowRunRequest> runs = List.of();
private List<KubeflowRunRequest> runs;
private int index = 0; private int index = 0;
@Override @Override
public KubeflowRunRequest read() { public KubeflowRunRequest read() {
if (!read) { // 페이지 끝나면 항상 최신 10개 fetch
if (index >= runs.size()) {
WebClient client = webClientBuilder().build(); WebClient client = webClientBuilder().build();
KubeflowRunResponse response = client.get() KubeflowRunResponse response = client.get()
.uri(uriBuilder -> uriBuilder .uri(uriBuilder -> uriBuilder
.path("/apis/v2beta1/runs") .path("/apis/v2beta1/runs")
.queryParam("page_size", PAGE_SIZE) .queryParam("page_size", PAGE_SIZE)
.queryParam("sort_by", "created_at desc")
.build()) .build())
.retrieve() .retrieve()
.bodyToMono(KubeflowRunResponse.class) .bodyToMono(KubeflowRunResponse.class)
.block(); .block();
runs = response != null ? response.getRuns() : List.of(); runs = response != null ? response.getRuns() : List.of();
read = true; index = 0;
}
if (runs != null && index < runs.size()) { // 데이터가 없으면 Step 종료
return runs.get(index++); if (runs.isEmpty()) {
return null;
}
} }
return null;
return runs.get(index++);
} }
}; };
} }
@Bean @Bean
public ItemProcessor<KubeflowRunRequest, KubeflowRunEntity> runProcessor() { public ItemProcessor<KubeflowRunRequest, KubeflowRunEntity> runProcessor() {
return dto -> { return dto -> {

@ -8,6 +8,5 @@ import java.util.List;
@Data @Data
public class KubeflowRunResponse { public class KubeflowRunResponse {
private List<KubeflowRunRequest> runs; private List<KubeflowRunRequest> runs;
private int total_size; private int totalSize;
private String next_page_token;
} }
Loading…
Cancel
Save