Skip to content

Commit

Permalink
Prevented to many GCode meta data updates if meta data request fails
Browse files Browse the repository at this point in the history
  • Loading branch information
Clon1998 committed Jun 2, 2024
1 parent 3be97bf commit 67aca5d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
9 changes: 6 additions & 3 deletions mobileraker/data/dtos/moonraker/printer_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ class GCodeFile:
def __init__(
self,
filename: str,
modified: float,
size: int,
modified: Optional[float] = None,
size: Optional[int] = None,
print_start_time: Optional[float] = None,
job_id: Optional[str] = None,
slicer: Optional[str] = None,
Expand Down Expand Up @@ -176,7 +176,10 @@ def __eq__(self, other):
return False

def __str__(self):
return f"Filename: {self.filename}, Modified: {self.modified}, Size: {self.size}"
return '%s(%s)' % (
type(self).__name__,
', '.join('%s=%s' % item for item in vars(self).items())
)

@classmethod
def from_json(cls, data_dict: Dict[str, Any]) -> 'GCodeFile':
Expand Down
6 changes: 6 additions & 0 deletions mobileraker/service/data_sync_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,12 @@ async def _fetch_gcode_meta(self, file_name: str) -> Optional[GCodeFile]:
meta, k_err = await self._jrpc.send_and_receive_method('server.files.metadata', {'filename': file_name})
if k_err:
self._logger.warning("Could not fetch metadata for %s. Moonraker returned error %s", file_name, k_err)

# If just no metadata is available, we return a GCodeFile instance with empty metadata, this prevents the service from fetching the metadata again.
if ('Metadata not availabe for' in k_err):
self._logger.warning("No metadata available for %s, returning empty GCodeFile instance", file_name)
return GCodeFile(filename=file_name)

return None
self._logger.debug("Metadata for %s: %s", file_name, meta)
return GCodeFile.from_json(meta['result'])
Expand Down

0 comments on commit 67aca5d

Please sign in to comment.