This commit is contained in:
@@ -17,6 +17,7 @@ import ru.soune.nocopy.entity.user.User;
|
|||||||
import ru.soune.nocopy.exception.InsufficientTokensException;
|
import ru.soune.nocopy.exception.InsufficientTokensException;
|
||||||
import ru.soune.nocopy.exception.SearchFailedException;
|
import ru.soune.nocopy.exception.SearchFailedException;
|
||||||
import ru.soune.nocopy.exception.TariffNotFoundException;
|
import ru.soune.nocopy.exception.TariffNotFoundException;
|
||||||
|
import ru.soune.nocopy.repository.FileEntityRepository;
|
||||||
import ru.soune.nocopy.repository.GlobalSearchResultRepository;
|
import ru.soune.nocopy.repository.GlobalSearchResultRepository;
|
||||||
import ru.soune.nocopy.repository.GlobalSearchTaskRepository;
|
import ru.soune.nocopy.repository.GlobalSearchTaskRepository;
|
||||||
import ru.soune.nocopy.repository.UserRepository;
|
import ru.soune.nocopy.repository.UserRepository;
|
||||||
@@ -53,6 +54,8 @@ public class GlobalSearchAsyncProcessor {
|
|||||||
|
|
||||||
private final EmailService emailService;
|
private final EmailService emailService;
|
||||||
|
|
||||||
|
private final FileEntityRepository fileEntityRepository;
|
||||||
|
|
||||||
// @Async
|
// @Async
|
||||||
// @Transactional
|
// @Transactional
|
||||||
// public void processFilesAsync(String taskId, List<FileEntity> filesToProcess, Long userId) {
|
// public void processFilesAsync(String taskId, List<FileEntity> filesToProcess, Long userId) {
|
||||||
@@ -97,7 +100,7 @@ public class GlobalSearchAsyncProcessor {
|
|||||||
FileEntity file = filesToProcess.get(i);
|
FileEntity file = filesToProcess.get(i);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
GlobalSearchResult result = processFile(file, taskId, userId);
|
GlobalSearchResult result = processFile(file.getId(), taskId, userId);
|
||||||
globalSearchResultRepository.save(result);
|
globalSearchResultRepository.save(result);
|
||||||
|
|
||||||
if (result.getFileStatus().equals(SearchStatus.FAILED.name()) ||
|
if (result.getFileStatus().equals(SearchStatus.FAILED.name()) ||
|
||||||
@@ -109,7 +112,6 @@ public class GlobalSearchAsyncProcessor {
|
|||||||
task.setProcessedFiles(i + 1);
|
task.setProcessedFiles(i + 1);
|
||||||
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.warn("Insufficient tokens for user {}, stopping task: {}", userId, taskId, e);
|
||||||
throw e;
|
throw e;
|
||||||
@@ -132,18 +134,13 @@ public class GlobalSearchAsyncProcessor {
|
|||||||
task.setUpdatedAt(LocalDateTime.now());
|
task.setUpdatedAt(LocalDateTime.now());
|
||||||
globalSearchTaskRepository.save(task);
|
globalSearchTaskRepository.save(task);
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("Global search failed for task: {}", taskId, e);
|
|
||||||
|
|
||||||
GlobalSearchTask task = globalSearchTaskRepository.findById(taskId).orElseThrow();
|
|
||||||
task.setStatus(SearchStatus.FAILED.name());
|
|
||||||
task.setUpdatedAt(LocalDateTime.now());
|
|
||||||
globalSearchTaskRepository.save(task);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private GlobalSearchResult processFile(FileEntity file, 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();
|
||||||
|
|
||||||
GlobalSearchResult result = new GlobalSearchResult();
|
GlobalSearchResult result = new GlobalSearchResult();
|
||||||
result.setTaskId(taskId);
|
result.setTaskId(taskId);
|
||||||
result.setFileId(file.getId());
|
result.setFileId(file.getId());
|
||||||
|
|||||||
Reference in New Issue
Block a user