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