refactor: skip completed jobs in file import command
This commit is contained in:
parent
c4ac020b11
commit
b14528476e
@ -21,6 +21,15 @@ public class FileImportConsumer {
|
|||||||
@RabbitListener(queues = "${queues.file-import}")
|
@RabbitListener(queues = "${queues.file-import}")
|
||||||
public void receiveFileImportCommand(FileImportCommand command) {
|
public void receiveFileImportCommand(FileImportCommand command) {
|
||||||
log.info("Received file import command: {}", 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 {
|
try {
|
||||||
contentImportService.importFile(
|
contentImportService.importFile(
|
||||||
command.mangaContentProviderId(), command.filename(), command.mangaImportJobId());
|
command.mangaContentProviderId(), command.filename(), command.mangaImportJobId());
|
||||||
|
|||||||
@ -208,6 +208,10 @@ public class ContentImportService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Optional<MangaImportJob> findImportJob(Long id) {
|
||||||
|
return mangaImportJobRepository.findById(id);
|
||||||
|
}
|
||||||
|
|
||||||
public List<MangaImportJobDTO> getImportJobs() {
|
public List<MangaImportJobDTO> getImportJobs() {
|
||||||
return mangaImportJobRepository.findAll(Sort.by(Sort.Direction.DESC, "updatedAt")).stream()
|
return mangaImportJobRepository.findAll(Sort.by(Sort.Direction.DESC, "updatedAt")).stream()
|
||||||
.map(MangaImportJobDTO::from)
|
.map(MangaImportJobDTO::from)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user