Use ai.retry settings, add AI connect timeout, stop logging post text
AiRetryProperties was bound but @Retryable had hard-coded values, so ai.retry.* in application.yaml had no effect. WebClient had no connect timeout (Netty default 30 s per attempt). TextModerationProcessor logged the whole moderation context, including post text, at INFO. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -20,8 +20,10 @@ public class ImageModerationClient {
|
||||
|
||||
@Retryable(
|
||||
retryFor = {AiUnavailableException.class, AiServerException.class, AiTimeoutException.class},
|
||||
maxAttempts = 3,
|
||||
backoff = @Backoff(delay = 500, multiplier = 2)
|
||||
// Параметры из ai.retry.* (AiRetryProperties); раньше они были захардкожены
|
||||
maxAttemptsExpression = "${ai.retry.max-attempts:3}",
|
||||
backoff = @Backoff(delayExpression = "${ai.retry.delay:500}",
|
||||
multiplierExpression = "${ai.retry.multiplier:2}")
|
||||
)
|
||||
public ImageModerationResponse moderate(MultipartFile file) {
|
||||
log.info("Calling AI ImageModeration service");
|
||||
|
||||
@@ -21,8 +21,10 @@ public class TextModerationClient {
|
||||
|
||||
@Retryable(
|
||||
retryFor = {AiUnavailableException.class, AiServerException.class, AiTimeoutException.class},
|
||||
maxAttempts = 3,
|
||||
backoff = @Backoff(delay = 500, multiplier = 2)
|
||||
// Параметры из ai.retry.* (AiRetryProperties); раньше они были захардкожены
|
||||
maxAttemptsExpression = "${ai.retry.max-attempts:3}",
|
||||
backoff = @Backoff(delayExpression = "${ai.retry.delay:500}",
|
||||
multiplierExpression = "${ai.retry.multiplier:2}")
|
||||
)
|
||||
public ModerationResponse moderate(String text) {
|
||||
log.info("Calling AI TextModeration service");
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.krylov.refound.ai.config;
|
||||
|
||||
import io.netty.channel.ChannelOption;
|
||||
import java.time.Duration;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import reactor.netty.http.client.HttpClient;
|
||||
@@ -14,11 +15,15 @@ import org.springframework.web.reactive.function.client.WebClient;
|
||||
@EnableConfigurationProperties(AiProperties.class)
|
||||
public class WebClientConfig {
|
||||
|
||||
private static final int CONNECT_TIMEOUT_MILLIS = 3_000;
|
||||
|
||||
@Bean
|
||||
public WebClient aiWebClient(AiProperties properties) {
|
||||
log.info("aiWebClient get for properties {}", properties);
|
||||
HttpClient httpClient =
|
||||
HttpClient.create()
|
||||
// Без явного таймаута соединения недоступный хост держал поток модерации ~30 с на попытку
|
||||
.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, CONNECT_TIMEOUT_MILLIS)
|
||||
.responseTimeout(
|
||||
Duration.ofSeconds(properties.getTimeout())
|
||||
);
|
||||
|
||||
@@ -27,7 +27,8 @@ public class TextModerationProcessor implements ModerationProcessor {
|
||||
|
||||
@Override
|
||||
public Boolean process(ModerationContext context) {
|
||||
log.info("process TextModerationProcessor for context {}", context);
|
||||
// Весь контекст (текст поста, файлы) в лог не пишем — только размер
|
||||
log.debug("process TextModerationProcessor: images={}", context.getImages() == null ? 0 : context.getImages().size());
|
||||
String text = buildText(
|
||||
context.getTitle(),
|
||||
context.getDescription()
|
||||
|
||||
Reference in New Issue
Block a user