db fix
This commit is contained in:
parent
62681cc80f
commit
5d52f423e0
|
|
@ -20,6 +20,7 @@ from requests.adapters import HTTPAdapter, Retry
|
|||
from urllib3.exceptions import InsecureRequestWarning
|
||||
|
||||
from .component import Component
|
||||
from ui.helpers import get_main_window
|
||||
# Suppress insecure request warning
|
||||
requests.packages.urllib3.disable_warnings(category=InsecureRequestWarning)
|
||||
|
||||
|
|
@ -27,6 +28,7 @@ requests.packages.urllib3.disable_warnings(category=InsecureRequestWarning)
|
|||
class ArchiveSynchronizer(Component):
|
||||
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.main_window = None
|
||||
self.simulate = "--sim-archiver" in sys.argv
|
||||
self.machine_status = "logged-in"
|
||||
self.machine_id = None
|
||||
|
|
@ -52,6 +54,10 @@ class ArchiveSynchronizer(Component):
|
|||
|
||||
@db.connection_context()
|
||||
def _get(self):
|
||||
if self.main_window is None:
|
||||
self.main_window = get_main_window()
|
||||
|
||||
|
||||
for record in list(Archive.select().where((Archive.archived != True) | (Archive.uploaded != True))): # using "is not True" breaks the query.. # list() forces the complete execution of the query unlocking the db unlike __enter__()
|
||||
if not self.simulate:
|
||||
if record.archived is not True:
|
||||
|
|
@ -60,7 +66,9 @@ class ArchiveSynchronizer(Component):
|
|||
record.uploaded = self.remote_store(record) is True
|
||||
else:
|
||||
self.log.info("simulated archive synchronizer cycle")
|
||||
record.save()
|
||||
#record.save()
|
||||
self.main_window.run_request.emit(record.save, [], {})
|
||||
|
||||
if self.hold_time > 0:
|
||||
QThread.msleep(self.hold_time)
|
||||
self.gcs_bucket = None
|
||||
|
|
@ -151,6 +159,8 @@ class ArchiveSynchronizer(Component):
|
|||
except (requests.ConnectionError, requests.Timeout) as e:
|
||||
self.log.warning(f"id: {record.id}: failed to archive remotely, archive_endpoint might be unreachable: {str(e)}")
|
||||
return False
|
||||
self.log.info(f"Archived successfully: {record.id}")
|
||||
|
||||
return True
|
||||
|
||||
def remote_store(self, record):
|
||||
|
|
@ -183,7 +193,7 @@ class ArchiveSynchronizer(Component):
|
|||
return False
|
||||
except Exception:
|
||||
self.log.error(f"id: {record.id}: failed to store remotely:\n{traceback.format_exc()}")
|
||||
self.log.info(f"id: {record.id}: stored remotely")
|
||||
self.log.info(f"Stored successfully: {record.id}")
|
||||
return True
|
||||
|
||||
def remote_fetch(self, remote_path=None, local_path=None):
|
||||
|
|
|
|||
|
|
@ -174,7 +174,6 @@ try:
|
|||
|
||||
# GUI INIT
|
||||
if "--no-gui" not in sys.argv:
|
||||
# self.main_window = Main_Window(self.bench)
|
||||
self.main_window = Main_Window()
|
||||
# CONNECT MAIN WINDOW ACTIONS
|
||||
self.main_window.logout_a.triggered.connect(lambda checked, selfie=weakref.ref(self): selfie().logout())
|
||||
|
|
|
|||
|
|
@ -1,2 +1,3 @@
|
|||
from .calc_foreground_color import calc_foreground_color
|
||||
from .get_main_window import get_main_window
|
||||
from .replace_widget import replace_widget
|
||||
|
|
|
|||
8
src/ui/helpers/get_main_window.py
Executable file
8
src/ui/helpers/get_main_window.py
Executable file
|
|
@ -0,0 +1,8 @@
|
|||
from PyQt5.QtWidgets import QApplication, QMainWindow
|
||||
|
||||
|
||||
def get_main_window():
|
||||
tws = QApplication.topLevelWidgets()
|
||||
for w in tws:
|
||||
if isinstance(w, QMainWindow):
|
||||
return w
|
||||
|
|
@ -5,10 +5,16 @@ from ui.window import Window
|
|||
|
||||
class Main_Window(Window):
|
||||
do = pyqtSignal(dict)
|
||||
run_request = pyqtSignal(object, list, dict)
|
||||
|
||||
@staticmethod
|
||||
def run_request_handler(fn, a, ka):
|
||||
fn(*a, **ka)
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.do.connect(self._do)
|
||||
self.run_request.connect(self.run_request_handler)
|
||||
# print("MAIN_WINDOW ", str(int(QThread.currentThreadId())), flush=True)
|
||||
|
||||
@staticmethod
|
||||
|
|
|
|||
|
|
@ -368,7 +368,9 @@ class Test(Widget):
|
|||
elif self.step.step_type == "print":
|
||||
compiled_label = self.print(self.archived, self.step.spec.get("template", "EtichettaR5"))
|
||||
self.archived.label = compiled_label
|
||||
self.archived.save()
|
||||
self.log.info(f"Label printed. Saving...")
|
||||
#self.archived.save()
|
||||
self.main_window.run_request.emit(self.archived.save, [], {})
|
||||
self.next_timer.start(500)
|
||||
elif self.step.step_type == "wait":
|
||||
self.next_timer.start(500)
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user