Skip to content

Commit 729d640

Browse files
authored
Keep track of active job id for file_progress and job_info messages. (#65)
1 parent 5b2b1e2 commit 729d640

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

octoprint_simplyprint/websocket/simplyprint.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ def __init__(self, plugin: SimplyPrint) -> None:
157157
self._last_ping_received: float = 0.
158158
self.gcode_terminal_enabled: bool = False
159159
self.cached_events: List[Tuple[Callable, Tuple[Any, ...]]] = []
160+
self._current_job_id: Optional[int] = None
160161

161162
# XXX: The call below is for dev, remove before release
162163
self._setup_simplyprint_logging()
@@ -586,6 +587,9 @@ def _process_demand(self, demand: str, args: Dict[str, Any]) -> None:
586587
file_id: Optional[str] = args.get("file_id")
587588
file_name: Optional[str] = args.get("file_name")
588589
start = bool(args.get("auto_start", 0))
590+
# Keep track of current job
591+
# Consider whether to persists this across restarts
592+
self._current_job_id = int(args.get("job_id", 0)) or None
589593

590594
if file_id != self.last_downloaded_file or self.file_manager.file_exists(FileDestinations.LOCAL, f"SimplyPrint/{file_name}") is False:
591595
self.last_downloaded_file = file_id
@@ -1417,6 +1421,11 @@ def send_sp(
14171421
fut = self._aioloop.create_future()
14181422
fut.set_result(False)
14191423
return fut
1424+
1425+
# Include tracked job_id with some message types.
1426+
if evt_name in ("file_progress", "job_info") and self._current_job_id is not None and isinstance(data, dict):
1427+
data.update({"job_id", self._current_job_id})
1428+
14201429
packet = {"type": evt_name, "data": data}
14211430
if evt_name != "stream":
14221431
self._sock_logger.info(f"sent: {packet}")

0 commit comments

Comments
 (0)