@@ -63,7 +63,8 @@ public class ImageFoundRequestHandler implements RequestHandler {
|
||||
|
||||
String yandexReverseSearchResponse;
|
||||
try {
|
||||
yandexReverseSearchResponse = yandexSearchService.searchReverseByPublicUrlWithTimeout(fileEntity, 20);
|
||||
yandexReverseSearchResponse = yandexSearchService.searchReverseByPublicUrlWithTimeout(fileEntity,
|
||||
20);
|
||||
} catch (TimeoutException e) {
|
||||
log.warn("Search timeout for file {}, returning empty results", fileId);
|
||||
return new BaseResponse(request.getMsgId(), MessageCode.SUCCESS.getCode(),
|
||||
|
||||
@@ -209,7 +209,6 @@ public class YandexSearchService {
|
||||
|
||||
public String searchReverseByPublicUrlWithTimeout(FileEntity fileEntity, int timeoutSeconds)
|
||||
throws IOException, TimeoutException {
|
||||
|
||||
if (!isImageFile(fileEntity)) {
|
||||
log.error("File not image: {}", fileEntity.getMimeType());
|
||||
throw new NotValidFieldException("File not image", new BaseResponse(20007,
|
||||
@@ -220,16 +219,13 @@ public class YandexSearchService {
|
||||
String publicUrl = String.format("%s/api/files/public/%s", appBaseUrl, fileEntity.getId());
|
||||
log.info("Searching reverse for image: {}", publicUrl);
|
||||
|
||||
// Создаем ExecutorService с одним потоком
|
||||
ExecutorService executor = Executors.newSingleThreadExecutor();
|
||||
|
||||
try {
|
||||
// Запускаем задачу с таймаутом
|
||||
Future<String> future = executor.submit(() ->
|
||||
callReverseImageApiByUrlWithTimeout(publicUrl, timeoutSeconds)
|
||||
);
|
||||
|
||||
// Получаем результат с таймаутом
|
||||
return future.get(timeoutSeconds, TimeUnit.SECONDS);
|
||||
|
||||
} catch (TimeoutException e) {
|
||||
|
||||
Reference in New Issue
Block a user