From 51fee3e7a13aba53c66cbf8c291969c2a448f342 Mon Sep 17 00:00:00 2001 From: Pedro Lamas Date: Thu, 22 Dec 2022 22:42:08 +0000 Subject: [PATCH] job_queue: add "reset" parameter to post endpoint Signed-off-by: Pedro Lamas --- moonraker/components/job_queue.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/moonraker/components/job_queue.py b/moonraker/components/job_queue.py index cf51c91..196fe2f 100644 --- a/moonraker/components/job_queue.py +++ b/moonraker/components/job_queue.py @@ -159,7 +159,8 @@ class JobQueue: async def queue_job(self, filenames: Union[str, List[str]], - check_exists: bool = True + check_exists: bool = True, + reset: bool = False ) -> None: async with self.lock: # Make sure that the file exists @@ -169,6 +170,8 @@ class JobQueue: # Make sure all files exist before adding them to the queue for fname in filenames: self._check_job_file(fname) + if reset: + self.queued_jobs.clear() for fname in filenames: queued_job = QueuedJob(fname) self.queued_jobs[queued_job.job_id] = queued_job @@ -249,10 +252,11 @@ class JobQueue: action = web_request.get_action() if action == "POST": files: Union[List[str], str] = web_request.get('filenames') + reset = web_request.get_boolean("reset", False) if isinstance(files, str): files = [f.strip() for f in files.split(',') if f.strip()] # Validate that all files exist before queueing - await self.queue_job(files) + await self.queue_job(files, reset=reset) elif action == "DELETE": if web_request.get_boolean("all", False): await self.delete_job([], all=True)