Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support persistent job ID from queue #970

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions moonraker/components/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import time
import logging
from asyncio import Lock
from uuid import uuid4
from ..common import (
JobEvent,
RequestType,
Expand Down Expand Up @@ -122,7 +123,7 @@ class HistorySqlDefinition(SqlTableDefinition):
prototype = (
f"""
{HIST_TABLE} (
job_id INTEGER PRIMARY KEY ASC,
job_id TEXT(36) PRIMARY KEY,
user TEXT NOT NULL,
filename TEXT,
status TEXT NOT NULL,
Expand Down Expand Up @@ -272,7 +273,7 @@ async def _handle_job_request(self,
if req_type == RequestType.GET:
job_id = web_request.get_str("uid")
cursor = await self.history_table.execute(
f"SELECT * FROM {HIST_TABLE} WHERE job_id = ?", (int(job_id, 16),)
f"SELECT * FROM {HIST_TABLE} WHERE job_id = ?", (job_id),
)
result = await cursor.fetchone()
if result is None:
Expand All @@ -298,7 +299,7 @@ async def _handle_job_request(self,
job_id = web_request.get_str("uid")
async with self.history_table as tx:
cursor = await tx.execute(
f"DELETE FROM {HIST_TABLE} WHERE job_id = ?", (int(job_id, 16),)
f"DELETE FROM {HIST_TABLE} WHERE job_id = ?", (job_id,)
)
if cursor.rowcount < 1:
raise self.server.error(f"Invalid job uid: {job_id}", 404)
Expand Down Expand Up @@ -421,7 +422,7 @@ async def add_job(self, job: PrinterJob) -> None:
logging.info(f"Error saving job, filename '{job.filename}'")
return
self.current_job_id = new_id
job_id = f"{new_id:06X}"
job_id = str(uuid4())
self.update_metadata(job_id)
logging.debug(
f"History Job Added - Id: {job_id}, File: {job.filename}"
Expand Down
3 changes: 2 additions & 1 deletion moonraker/components/job_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import time
import logging
from ..common import JobEvent, RequestType
from uuid import uuid4

# Annotation imports
from typing import (
Expand Down Expand Up @@ -334,7 +335,7 @@ async def close(self):
class QueuedJob:
def __init__(self, filename: str, user: Optional[UserInfo] = None) -> None:
self.filename = filename
self.job_id = f"{id(self):016X}"
self.job_id = str(uuid4())
self.time_added = time.time()
self._user = user

Expand Down
Loading