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:
SlimusMinus
2026-10-20 01:04:30 +03:00
parent a909b1f08b
commit 3fd045131c
4 changed files with 15 additions and 5 deletions

View File

@@ -20,8 +20,10 @@ public class ImageModerationClient {
@Retryable( @Retryable(
retryFor = {AiUnavailableException.class, AiServerException.class, AiTimeoutException.class}, retryFor = {AiUnavailableException.class, AiServerException.class, AiTimeoutException.class},
maxAttempts = 3, // Параметры из ai.retry.* (AiRetryProperties); раньше они были захардкожены
backoff = @Backoff(delay = 500, multiplier = 2) maxAttemptsExpression = "${ai.retry.max-attempts:3}",
backoff = @Backoff(delayExpression = "${ai.retry.delay:500}",
multiplierExpression = "${ai.retry.multiplier:2}")
) )
public ImageModerationResponse moderate(MultipartFile file) { public ImageModerationResponse moderate(MultipartFile file) {
log.info("Calling AI ImageModeration service"); log.info("Calling AI ImageModeration service");

View File

@@ -21,8 +21,10 @@ public class TextModerationClient {
@Retryable( @Retryable(
retryFor = {AiUnavailableException.class, AiServerException.class, AiTimeoutException.class}, retryFor = {AiUnavailableException.class, AiServerException.class, AiTimeoutException.class},
maxAttempts = 3, // Параметры из ai.retry.* (AiRetryProperties); раньше они были захардкожены
backoff = @Backoff(delay = 500, multiplier = 2) maxAttemptsExpression = "${ai.retry.max-attempts:3}",
backoff = @Backoff(delayExpression = "${ai.retry.delay:500}",
multiplierExpression = "${ai.retry.multiplier:2}")
) )
public ModerationResponse moderate(String text) { public ModerationResponse moderate(String text) {
log.info("Calling AI TextModeration service"); log.info("Calling AI TextModeration service");

View File

@@ -1,5 +1,6 @@
package com.krylov.refound.ai.config; package com.krylov.refound.ai.config;
import io.netty.channel.ChannelOption;
import java.time.Duration; import java.time.Duration;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import reactor.netty.http.client.HttpClient; import reactor.netty.http.client.HttpClient;
@@ -14,11 +15,15 @@ import org.springframework.web.reactive.function.client.WebClient;
@EnableConfigurationProperties(AiProperties.class) @EnableConfigurationProperties(AiProperties.class)
public class WebClientConfig { public class WebClientConfig {
private static final int CONNECT_TIMEOUT_MILLIS = 3_000;
@Bean @Bean
public WebClient aiWebClient(AiProperties properties) { public WebClient aiWebClient(AiProperties properties) {
log.info("aiWebClient get for properties {}", properties); log.info("aiWebClient get for properties {}", properties);
HttpClient httpClient = HttpClient httpClient =
HttpClient.create() HttpClient.create()
// Без явного таймаута соединения недоступный хост держал поток модерации ~30 с на попытку
.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, CONNECT_TIMEOUT_MILLIS)
.responseTimeout( .responseTimeout(
Duration.ofSeconds(properties.getTimeout()) Duration.ofSeconds(properties.getTimeout())
); );

View File

@@ -27,7 +27,8 @@ public class TextModerationProcessor implements ModerationProcessor {
@Override @Override
public Boolean process(ModerationContext context) { 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( String text = buildText(
context.getTitle(), context.getTitle(),
context.getDescription() context.getDescription()