fixed ai image timeout
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user