ADD JobService and UploadService

This commit is contained in:
2025-05-05 21:12:35 +02:00
parent 9f9e8251f9
commit da5d2ef853
5 changed files with 162 additions and 40 deletions

View File

@@ -0,0 +1,45 @@
package com.ddf.vodsystem.services;
import com.ddf.vodsystem.entities.Job;
import jakarta.annotation.PostConstruct;
import org.springframework.stereotype.Service;
import java.util.LinkedList;
@Service
public class JobService {
private LinkedList<Job> jobs = new LinkedList<>();
public void addJob(Job job) {
jobs.add(job);
}
public Job getNextJob() {
return jobs.remove();
}
public Job getJob(String uuid){
for (Job job : jobs) {
if(job.getUuid().equals(uuid)){
return job;
}
}
throw new RuntimeException("UUID not found");
}
@PostConstruct
public void startProcessingLoop() {
Thread thread = new Thread(() -> {
while (true) {
if (!jobs.isEmpty()) {
Runnable task = getNextJob();
task.run(); // Execute the task
}
}
});
thread.setDaemon(true);
thread.start();
}
}