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

This commit is contained in:
vladp
2026-03-30 13:21:11 +07:00
parent 976d1f751e
commit 7af909c4f2
@@ -111,7 +111,7 @@ public class GlobalSearchAsyncProcessor {
globalSearchTaskRepository.save(task);
} catch (InsufficientTokensException e) {
log.warn("Insufficient tokens for user {}, stopping task: {}", userId, taskId);
log.warn("Insufficient tokens for user {}, stopping task: {}", userId, taskId, e);
throw e;
} catch (Exception e) {
log.error("Error processing file {} in task {}", file.getId(), taskId, e);
@@ -124,6 +124,14 @@ public class GlobalSearchAsyncProcessor {
task.setUpdatedAt(LocalDateTime.now());
globalSearchTaskRepository.save(task);
} catch (InsufficientTokensException e) {
log.error("Task {} failed due to insufficient tokens for user {}", taskId, userId, e);
GlobalSearchTask task = globalSearchTaskRepository.findById(taskId).orElseThrow();
task.setStatus(SearchStatus.FAILED.name());
task.setUpdatedAt(LocalDateTime.now());
globalSearchTaskRepository.save(task);
} catch (Exception e) {
log.error("Global search failed for task: {}", taskId, e);
@@ -134,7 +142,8 @@ public class GlobalSearchAsyncProcessor {
}
}
private GlobalSearchResult processFile(FileEntity file, String taskId, Long userId) throws MessagingException, IOException {
private GlobalSearchResult processFile(FileEntity file, String taskId, Long userId) throws MessagingException,
IOException, InsufficientTokensException {
GlobalSearchResult result = new GlobalSearchResult();
result.setTaskId(taskId);
result.setFileId(file.getId());
@@ -147,8 +156,9 @@ public class GlobalSearchAsyncProcessor {
TariffInfo activeTariffInfo = user.getActiveTariffInfo();
int currentTokens = activeTariffInfo.getTokens() + activeTariffInfo.getBoughtTokens();
log.info("Before sending email for user: {}", user.getEmail());
emailService.sendTokensNotFoundEmail(user, currentTokens, TariffConstants.TOKEN_VALUE_FOR_SEARCH);
log.info("Email sent successfully to user: {}", user.getEmail());
result.setFileStatus(SearchStatus.FAILED.name());
globalSearchResultRepository.save(result);