Ensure that jobs are enqueued after application restart.
Jobs that are in state of PROCESSING or PENDING will be enqueued after application restart so users that have had an uploaded file in PROCESSING or PENDING do not need to manually re-upload the files again.
This commit is contained in:
parent
9f186c8406
commit
af439dda32
@ -15,6 +15,7 @@ import se.su.dsv.seshat.repositories.FileMetadataRepository;
|
||||
|
||||
import java.io.File;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
@ -62,12 +63,21 @@ public class JobProcessorService {
|
||||
worker.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add all jobs that have been in a processing status or pending status
|
||||
* to the queue when the application starts.
|
||||
* Ensuring that all jobs are processed even if the application is restarted
|
||||
* wihtout the user having to re-upload the files.
|
||||
*/
|
||||
@Transactional
|
||||
public void addPendingJobsToQueue() {
|
||||
List<FileMetadata> pendingJobs = fileMetadataRepository.findByJobStatus(JobStatus.PENDING);
|
||||
for (FileMetadata job : pendingJobs) {
|
||||
jobQueue.offer(job);
|
||||
}
|
||||
List<FileMetadata> processingJobs = fileMetadataRepository.findByJobStatus(JobStatus.PROCESSING);
|
||||
processingJobs.addAll(fileMetadataRepository.findByJobStatus(JobStatus.PENDING));
|
||||
|
||||
processingJobs.sort(Comparator.comparing(FileMetadata::getUploadedAt));
|
||||
|
||||
processingJobs.forEach(this::addJob);
|
||||
|
||||
}
|
||||
|
||||
@Transactional
|
||||
|
Loading…
x
Reference in New Issue
Block a user