job_queue: dont attempt to start a print when empty

Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
Eric Callahan 2021-11-26 19:53:57 -05:00
parent 784b8b9b18
commit 28e88b1363
2 changed files with 4 additions and 22 deletions

View File

@ -535,9 +535,9 @@ class FileManager:
started = True
if self.queue_gcodes and not started:
job_queue: JobQueue = self.server.lookup_component('job_queue')
started = await job_queue.queue_job(
await job_queue.queue_job(
upload_info['filename'], check_exists=False)
queued = not started
queued = True
await self.notify_sync_lock.wait(300.)
self.notify_sync_lock = None

View File

@ -28,10 +28,10 @@ class JobQueue:
def __init__(self, config: ConfigHelper) -> None:
self.server = config.get_server()
self.queued_jobs: Dict[str, QueuedJob] = {}
self.queue_state: str = "ready"
self.lock = asyncio.Lock()
self.load_on_start = config.getboolean("load_on_startup", False)
self.automatic = config.getboolean("automatic_transition", False)
self.queue_state: str = "ready" if self.automatic else "paused"
self.job_delay = config.getfloat("job_transition_delay", 0.01)
if self.job_delay <= 0.:
raise config.error(
@ -150,31 +150,13 @@ class JobQueue:
async def queue_job(self, filename: str,
check_exists: bool = True
) -> bool:
) -> None:
async with self.lock:
# Make sure that the file exists
if check_exists:
self._check_job_file(filename)
can_print = await self._check_can_print()
if (
self.queue_state == "ready" and
not self.queued_jobs and
can_print
):
# Printer is ready to accept a print
kapis: KlippyAPI = self.server.lookup_component('klippy_apis')
try:
await kapis.start_print(filename)
except self.server.error:
# Attempt to start print failed, queue the print
pass
else:
return True
if not self.automatic and self.queue_state == "ready":
self.queue_state == "paused"
queued_job = QueuedJob(filename)
self.queued_jobs[queued_job.job_id] = queued_job
return False
async def pause_queue(self) -> None:
self.queue_state = "paused"