Skip to content

Commit 0c7000f

Browse files
committed
feat: 비동기처리-threadPool 적용 & 이슈리스트 DB조회 로직 구현
1 parent fa18079 commit 0c7000f

File tree

5 files changed

+338
-155
lines changed

5 files changed

+338
-155
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package Capstone.FOSSistant.global.config;
2+
3+
import org.springframework.context.annotation.Bean;
4+
import org.springframework.context.annotation.Configuration;
5+
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
6+
7+
@Configuration
8+
public class AsyncConfig {
9+
10+
@Bean("classifierExecutor")
11+
public ThreadPoolTaskExecutor classifierExecutor() {
12+
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
13+
executor.setCorePoolSize(10); // 최소 10개 스레드 유지
14+
executor.setMaxPoolSize(50); // 최대 50개 스레드까지 확장
15+
executor.setQueueCapacity(100); // 작업 대기 큐 크기
16+
executor.setThreadNamePrefix("AI-Clf-"); // 스레드 이름 접두어
17+
executor.initialize();
18+
return executor;
19+
}
20+
}

src/main/java/Capstone/FOSSistant/global/service/customAI/AIClassifierClient.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public class AIClassifierClient {
2424
private final ObjectMapper objectMapper = new ObjectMapper();
2525

2626
public Mono<String> classify(String title, String body) {
27-
String shortBody = (body == null || body.isBlank()) ? "(no description provided)" : body;
27+
String shortBody = (body == null || body.isBlank()) ? "" : body;
2828
shortBody = shortBody.replaceAll("(?s)```.*?```", "");
2929

3030
long start = System.currentTimeMillis();
@@ -81,7 +81,7 @@ public Mono<String> classifyBatch(List<String[]> titleBodyList) {
8181
.map(pair -> Map.of(
8282
"title", pair[0],
8383
"body", (pair[1] == null || pair[1].isBlank())
84-
? "(no description provided)"
84+
? ""
8585
: pair[1].replaceAll("(?s)```.*?```", "")
8686
))
8787
.toList();
@@ -107,7 +107,7 @@ public Mono<String> classifyBatch(List<String[]> titleBodyList) {
107107
.retrieve()
108108
.bodyToMono(String.class)
109109
.timeout(Duration.ofSeconds(30))
110-
.doOnSuccess(result -> {
110+
.doOnSuccess( result -> {
111111
long end = System.currentTimeMillis();
112112
log.info("[AI Batch API 호출 + 응답 수신 시간] {}ms", (end - start));
113113
})
@@ -128,4 +128,17 @@ public Mono<String> classifyBatch(List<String[]> titleBodyList) {
128128
return Mono.just("{\"results\": []}");
129129
});
130130
}
131+
/**
132+
* 단건 기본값: difficulty="misc" 하나를 리턴
133+
*/
134+
public Mono<String> defaultSingleResult() {
135+
return Mono.just("{\"results\":[{\"difficulty\":\"misc\",\"score\":0.0}]}");
136+
}
137+
138+
/**
139+
* 배치 기본값: 빈 리스트
140+
*/
141+
public Mono<String> defaultBatchResult() {
142+
return Mono.just("{\"results\":[]}");
143+
}
131144
}

0 commit comments

Comments
 (0)