package com.kamco.cd.training.config;

import java.util.concurrent.Executor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

@Configuration
@EnableAsync
public class AsyncConfig {

  @Bean(name = "trainJobExecutor")
  public Executor trainJobExecutor() {
    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    executor.setCorePoolSize(4); // 동시에 4개 실행
    executor.setMaxPoolSize(8); // 최대 8개
    executor.setQueueCapacity(200); // 대기 큐
    executor.setThreadNamePrefix("train-job-");
    executor.initialize();
    return executor;
  }

  @Bean("datasetExecutor")
  public Executor datasetExecutor() {

    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();

    executor.setCorePoolSize(5);
    executor.setMaxPoolSize(10);
    executor.setQueueCapacity(100);
    executor.setThreadNamePrefix("dataset-");

    executor.initialize();
    return executor;
  }
}
