dev email send when tokens not found
Test Workflow / test (push) Successful in 2s

This commit is contained in:
vladp
2026-03-30 13:48:10 +07:00
parent 41ac8933e9
commit 2445b70c7a
@@ -5,6 +5,7 @@ import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async; import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import ru.soune.nocopy.configuration.search.SearchProperties; import ru.soune.nocopy.configuration.search.SearchProperties;
import ru.soune.nocopy.dto.file.YandexSearchResponse; import ru.soune.nocopy.dto.file.YandexSearchResponse;
@@ -113,11 +114,14 @@ public class GlobalSearchAsyncProcessor {
task.setUpdatedAt(LocalDateTime.now()); task.setUpdatedAt(LocalDateTime.now());
globalSearchTaskRepository.save(task); globalSearchTaskRepository.save(task);
} catch (InsufficientTokensException e) { } catch (InsufficientTokensException e) {
log.warn("Insufficient tokens for user {}, stopping task: {}", userId, taskId, e); log.error("Task {} failed due to insufficient tokens for user {}", taskId, userId, e);
throw e;
updateTaskStatus(taskId, SearchStatus.FAILED.name());
} catch (Exception e) { } catch (Exception e) {
log.error("Error processing file {} in task {}", file.getId(), taskId, e); log.error("Global search failed for task: {}", taskId, e);
throw new SearchFailedException("Failed to process file: " + file.getId());
updateTaskStatus(taskId, SearchStatus.FAILED.name());
} }
} }
@@ -137,6 +141,18 @@ public class GlobalSearchAsyncProcessor {
} }
} }
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void updateTaskStatus(String taskId, String status) {
try {
GlobalSearchTask task = globalSearchTaskRepository.findById(taskId).orElseThrow();
task.setStatus(status);
task.setUpdatedAt(LocalDateTime.now());
globalSearchTaskRepository.save(task);
} catch (Exception e) {
log.error("Failed to update task status for task: {}", taskId, e);
}
}
private GlobalSearchResult processFile(String fileId, String taskId, Long userId) throws MessagingException, private GlobalSearchResult processFile(String fileId, String taskId, Long userId) throws MessagingException,
IOException, InsufficientTokensException { IOException, InsufficientTokensException {
FileEntity file = fileEntityRepository.findById(fileId).orElseThrow(); FileEntity file = fileEntityRepository.findById(fileId).orElseThrow();