This commit is contained in:
neo 2024-09-18 18:15:01 +02:00
parent e7fc30d5f6
commit 938e420800
2 changed files with 7 additions and 19 deletions

View File

@ -19,11 +19,10 @@ from .component import Component
# Suppress insecure request warning
requests.packages.urllib3.disable_warnings(category=InsecureRequestWarning)
class ArchiveSynchronizer(Component):
machine_status = "offline"
def __init__(self, config=None, name=None, period=1, lazy=True, paused=False, threaded=True):
super().__init__(config=config, name=name, period=period, lazy=lazy, paused=paused, threaded=threaded)
self.simulate = "--sim-archiver" in sys.argv
self.status= ArchiveSynchronizer.machine_status
self.machine_status = "offline"
def config_changed(self):
self.machine_id = self.config.machine_id
@ -31,8 +30,6 @@ class ArchiveSynchronizer(Component):
self.archive_endpoint =f"https://dev.r5portal.it/api/st-ten-save/"
else:
self.archive_endpoint = self.config[self.name]["archive_endpoint"]
#self.status_endpoint = f"https://dev.r5portal.it/api/device-info-update?machine-id={self.machine_id_endpoint}&status={self.status}"
# self.images_path = self.config[self.name]["images_path"]
self._do_set_period({"period": float(self.config[self.name]["poll_time"])})
self.hold_time = round(float(self.config[self.name]["hold_time"]) * 1000)
self.gcs_client = storage.Client.from_service_account_json(self.config[self.name]["service_account_json"])
@ -60,14 +57,9 @@ class ArchiveSynchronizer(Component):
super()._get()
def update_machine_status(self):
self.status = ArchiveSynchronizer.machine_status
#print(f"machine_status_global: {ArchiveSynchronizer.machine_status}") # TESTING
self.status_endpoint = f"https://dev.r5portal.it/api/device-info-update?machine-id={self.machine_id.upper()}&status={self.status}"
self.status_endpoint = f"https://dev.r5portal.it/api/device-info-update?machine-id={self.machine_id.upper()}&status={self.machine_status}"
if self.status not in ["working", "logged-in", "logged-out"]:
status_dict = {"last_status": "offline"}
else:
status_dict = {"last_status": self.status}
status_dict = {"last_status": self.machine_status}
response = None
try:
@ -79,21 +71,21 @@ class ArchiveSynchronizer(Component):
raise AssertionError("bad status response")
except AssertionError as e:
self.log.warning(
f"Status: {self.status}: failed to update machine status: {str(e)}: {response.status_code if response else 'no response'}: {response.content if response else 'no response'}"
f"Status: {self.machine_status}: failed to update machine status: {str(e)}: {response.status_code if response else 'no response'}: {response.content if response else 'no response'}"
)
return False
except (requests.ConnectionError, requests.Timeout) as e:
self.log.warning(
f"Status: {self.status}: failed to update machine status, archive_endpoint might be unreachable: {str(e)}"
f"Status: {self.machine_status}: failed to update machine status, archive_endpoint might be unreachable: {str(e)}"
)
return False
except Exception:
self.log.error(
f"Status: {self.status}: failed to update machine status:\n{traceback.format_exc()}:\n{response.status_code if response else 'no response'}: {response.content if response else 'no response'}"
f"Status: {self.machine_status}: failed to update machine status:\n{traceback.format_exc()}:\n{response.status_code if response else 'no response'}: {response.content if response else 'no response'}"
)
return False
self.log.info(f"Status: {self.status}: Machine Status Updated Successfully")
self.log.info(f"Status: {self.machine_status}: Machine Status Updated Successfully")
return True
def remote_archive(self, record):
r = None

View File

@ -4,7 +4,6 @@ import os
import sys
import weakref
from datetime import datetime, timedelta
from components import ArchiveSynchronizer
from PyQt5.QtCore import QTimer, pyqtSlot
from PyQt5.QtWidgets import QMessageBox
from lib.db import Archive, Recipes, Users
@ -254,9 +253,6 @@ class Test(Widget):
else:
self.log.info(f"cycle step: {self.step!r} action: {action!r} current index:{self.cycle_index}")
ArchiveSynchronizer.machine_status = "working"
# print(f"{ArchiveSynchronizer.machine_status}")#testing
current_w = self.centralWidget
if hasattr(current_w, "stop"):
current_w.stop()