refactor: skip completed jobs in file import command

This commit is contained in:
Rodrigo Verdiani 2026-03-28 08:24:17 -03:00
parent c4ac020b11
commit b14528476e
2 changed files with 13 additions and 0 deletions

View File

@ -21,6 +21,15 @@ public class FileImportConsumer {
@RabbitListener(queues = "${queues.file-import}")
public void receiveFileImportCommand(FileImportCommand command) {
log.info("Received file import command: {}", command);
if (nonNull(command.mangaImportJobId())) {
var job = contentImportService.findImportJob(command.mangaImportJobId());
if (job.isPresent() && job.get().getStatus().equals(ImportJobStatus.SUCCESS)) {
log.info("Job {} already completed, skipping", command.mangaImportJobId());
return;
}
}
try {
contentImportService.importFile(
command.mangaContentProviderId(), command.filename(), command.mangaImportJobId());

View File

@ -208,6 +208,10 @@ public class ContentImportService {
}
}
public Optional<MangaImportJob> findImportJob(Long id) {
return mangaImportJobRepository.findById(id);
}
public List<MangaImportJobDTO> getImportJobs() {
return mangaImportJobRepository.findAll(Sort.by(Sort.Direction.DESC, "updatedAt")).stream()
.map(MangaImportJobDTO::from)