gitlab-runner-gateway/src/main/java/tk/antoine_roux/wiki/service/JobManager.java

28 lines
893 B
Java
Raw Normal View History

package tk.antoine_roux.wiki.service;
import org.springframework.stereotype.Service;
import tk.antoine_roux.wiki.model.request.JobRequest;
2020-10-03 15:03:48 +00:00
import tk.antoine_roux.wiki.model.request.HookEvent;
import tk.antoine_roux.wiki.model.response.JobResponse;
import java.util.Optional;
import java.util.concurrent.ConcurrentLinkedQueue;
@Service
public class JobManager {
/**
2020-10-03 15:03:48 +00:00
* concurrent list of {@link JobResponse} fill by {@link tk.antoine_roux.wiki.ControllerHandlers#webhook(HookEvent)}
* and pop by {@link tk.antoine_roux.wiki.ControllerHandlers#jobRequest(JobRequest)}
*/
2020-10-03 15:03:48 +00:00
ConcurrentLinkedQueue<JobResponse> jobQueue = new ConcurrentLinkedQueue<>();
2020-10-03 15:03:48 +00:00
public void stackJob(JobResponse newJob) {
this.jobQueue.add(newJob);
}
2020-10-03 15:03:48 +00:00
public Optional<JobResponse> popJob(JobRequest jobRequest) {
return Optional.ofNullable(this.jobQueue.poll());
}
}