fixed ai image timeout

This commit is contained in:
SlimusMinus
2026-10-15 00:48:58 +03:00
parent 13bb0c8503
commit c83d41a036
8 changed files with 218 additions and 20 deletions

View File

@@ -3,6 +3,7 @@ package com.krylov.refound.ai.client;
import com.krylov.refound.ai.dto.ModerationResponse;
import com.krylov.refound.ai.dto.TextModerationRequest;
import com.krylov.refound.ai.exception.AiServerException;
import com.krylov.refound.ai.exception.AiTimeoutException;
import com.krylov.refound.ai.exception.AiUnavailableException;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@@ -19,7 +20,7 @@ public class TextModerationClient {
private final AiHttpClient client;
@Retryable(
retryFor = {AiUnavailableException.class, AiServerException.class},
retryFor = {AiUnavailableException.class, AiServerException.class, AiTimeoutException.class},
maxAttempts = 3,
backoff = @Backoff(delay = 500, multiplier = 2)
)
@@ -28,16 +29,25 @@ public class TextModerationClient {
return client.post("/api/v1/moderation/text", new TextModerationRequest(text), ModerationResponse.class);
}
// После исчерпания попыток возвращаем null: пост остаётся на модерации и
// проверяется снова при следующем запуске планировщика.
@Recover
public ModerationResponse recover(AiUnavailableException e, String text) {
log.error("AI TextModeration unavailable after retries", e);
log.error("AI TextModeration unavailable after retries: {}", e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
return null;
}
@Recover
public ModerationResponse recover(AiTimeoutException e, String text) {
log.error("AI TextModeration timed out after retries");
return null;
}
@Recover
public ModerationResponse recover(AiServerException e, String text) {
log.error("AI TextModeration server error after retries", e);
log.error("AI TextModeration server error after retries: {}", e.getMessage());
return null;
}