job_queue: add "reset" parameter to post endpoint
Signed-off-by: Pedro Lamas <pedrolamas@gmail.com>
This commit is contained in:
parent
f7d8af6e12
commit
51fee3e7a1
|
@ -159,7 +159,8 @@ class JobQueue:
|
||||||
|
|
||||||
async def queue_job(self,
|
async def queue_job(self,
|
||||||
filenames: Union[str, List[str]],
|
filenames: Union[str, List[str]],
|
||||||
check_exists: bool = True
|
check_exists: bool = True,
|
||||||
|
reset: bool = False
|
||||||
) -> None:
|
) -> None:
|
||||||
async with self.lock:
|
async with self.lock:
|
||||||
# Make sure that the file exists
|
# Make sure that the file exists
|
||||||
|
@ -169,6 +170,8 @@ class JobQueue:
|
||||||
# Make sure all files exist before adding them to the queue
|
# Make sure all files exist before adding them to the queue
|
||||||
for fname in filenames:
|
for fname in filenames:
|
||||||
self._check_job_file(fname)
|
self._check_job_file(fname)
|
||||||
|
if reset:
|
||||||
|
self.queued_jobs.clear()
|
||||||
for fname in filenames:
|
for fname in filenames:
|
||||||
queued_job = QueuedJob(fname)
|
queued_job = QueuedJob(fname)
|
||||||
self.queued_jobs[queued_job.job_id] = queued_job
|
self.queued_jobs[queued_job.job_id] = queued_job
|
||||||
|
@ -249,10 +252,11 @@ class JobQueue:
|
||||||
action = web_request.get_action()
|
action = web_request.get_action()
|
||||||
if action == "POST":
|
if action == "POST":
|
||||||
files: Union[List[str], str] = web_request.get('filenames')
|
files: Union[List[str], str] = web_request.get('filenames')
|
||||||
|
reset = web_request.get_boolean("reset", False)
|
||||||
if isinstance(files, str):
|
if isinstance(files, str):
|
||||||
files = [f.strip() for f in files.split(',') if f.strip()]
|
files = [f.strip() for f in files.split(',') if f.strip()]
|
||||||
# Validate that all files exist before queueing
|
# Validate that all files exist before queueing
|
||||||
await self.queue_job(files)
|
await self.queue_job(files, reset=reset)
|
||||||
elif action == "DELETE":
|
elif action == "DELETE":
|
||||||
if web_request.get_boolean("all", False):
|
if web_request.get_boolean("all", False):
|
||||||
await self.delete_job([], all=True)
|
await self.delete_job([], all=True)
|
||||||
|
|
Loading…
Reference in New Issue