From 129b0feb812695274c0d6d654a0ccec917ad87db Mon Sep 17 00:00:00 2001 From: Eric Callahan Date: Thu, 22 Dec 2022 12:48:23 -0500 Subject: [PATCH] job_queue: add "jump" endpoint Signed-off-by: Eric Callahan --- moonraker/components/job_queue.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/moonraker/components/job_queue.py b/moonraker/components/job_queue.py index c232ba9..cf51c91 100644 --- a/moonraker/components/job_queue.py +++ b/moonraker/components/job_queue.py @@ -66,6 +66,8 @@ class JobQueue: "/server/job_queue/start", ['POST'], self._handle_start_queue) self.server.register_endpoint( "/server/job_queue/status", ['GET'], self._handle_queue_status) + self.server.register_endpoint( + "/server/job_queue/jump", ['POST'], self._handle_jump) async def _handle_ready(self) -> None: async with self.lock: @@ -293,6 +295,20 @@ class JobQueue: 'queue_state': self.queue_state } + async def _handle_jump(self, web_request: WebRequest) -> Dict[str, Any]: + job_id: str = web_request.get("job_id") + async with self.lock: + job = self.queued_jobs.pop(job_id, None) + if job is None: + raise self.server.error(f"Invalid job id: {job_id}") + new_queue = {job_id: job} + new_queue.update(self.queued_jobs) + self.queued_jobs = new_queue + return { + 'queued_jobs': self._job_map_to_list(), + 'queue_state': self.queue_state + } + async def close(self): await self.pause_queue()