job_queue: add "jump" endpoint

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
Eric Callahan 2022-12-22 12:48:23 -05:00
parent f296c6fadd
commit 129b0feb81
No known key found for this signature in database
GPG Key ID: 5A1EB336DFB4C71B
1 changed files with 16 additions and 0 deletions

View File

@ -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()