Add connect_timout to DBManager connection and accelerate program start
on connection timeout
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
# This Python file uses the following encoding: utf-8
|
|
||||||
import mariadb
|
import mariadb
|
||||||
|
|
||||||
class DbManager(object):
|
class DbManager():
|
||||||
__connection = None
|
__connection = None
|
||||||
__con_param = None
|
__con_param = None
|
||||||
__dbmanager = None
|
__dbmanager = None
|
||||||
@@ -14,7 +13,6 @@ class DbManager(object):
|
|||||||
|
|
||||||
return cls.__dbmanager
|
return cls.__dbmanager
|
||||||
|
|
||||||
|
|
||||||
def getConnection(cls):
|
def getConnection(cls):
|
||||||
#print(f"DB Manager: {cls.__dbmanager}")
|
#print(f"DB Manager: {cls.__dbmanager}")
|
||||||
#print(f"DB Connection: {cls.__connection}")
|
#print(f"DB Connection: {cls.__connection}")
|
||||||
@@ -26,7 +24,10 @@ class DbManager(object):
|
|||||||
cls.__connection = mariadb.connect(**cls.__con_param)
|
cls.__connection = mariadb.connect(**cls.__con_param)
|
||||||
print(f"DbManager Connection (INTERFACE ERROR): {e}..reconnecting...")
|
print(f"DbManager Connection (INTERFACE ERROR): {e}..reconnecting...")
|
||||||
except mariadb.Error as e:
|
except mariadb.Error as e:
|
||||||
print(f"File: {__file__}\n Database connection error: {e}")
|
if '(110)' in str(e):
|
||||||
|
print(f"File: {__file__}\n Database connection timed out (Check connection parameters or server): {e}")
|
||||||
|
else:
|
||||||
|
print(f"File: {__file__}\n Database connection error: {e}")
|
||||||
cls.__connection = None
|
cls.__connection = None
|
||||||
|
|
||||||
return cls.__connection
|
return cls.__connection
|
||||||
@@ -34,7 +35,7 @@ class DbManager(object):
|
|||||||
def __initializeConfig(cls, dbconf):
|
def __initializeConfig(cls, dbconf):
|
||||||
cls.__con_param = { 'user': dbconf['DB_USER'], 'password': dbconf['DB_PASS'],
|
cls.__con_param = { 'user': dbconf['DB_USER'], 'password': dbconf['DB_PASS'],
|
||||||
'port': int (dbconf['DB_PORT']), 'host': dbconf['DB_HOST'],
|
'port': int (dbconf['DB_PORT']), 'host': dbconf['DB_HOST'],
|
||||||
'database': dbconf['DB_NAME']
|
'database': dbconf['DB_NAME'], 'connect_timeout': 5
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
21
main.py
21
main.py
@@ -1,4 +1,4 @@
|
|||||||
# This Python file uses the following encoding: utf-8
|
# # !/home/linuxero/proj/tero/pyqcrm/.qtcreator/venv-3.13.0/bin/python3
|
||||||
import sys
|
import sys
|
||||||
import logging
|
import logging
|
||||||
from PySide6.QtGui import QGuiApplication
|
from PySide6.QtGui import QGuiApplication
|
||||||
@@ -37,18 +37,19 @@ user = None
|
|||||||
|
|
||||||
def initializeProgram():
|
def initializeProgram():
|
||||||
#print(f"In {__file__} file, initializeProgram()")
|
#print(f"In {__file__} file, initializeProgram()")
|
||||||
global address_model, bad_config, business_model, user, business_type, contact_model
|
global address_model, bad_config, business_model, user, business_type, contact_model, db_con
|
||||||
if not bad_config:
|
if not bad_config:
|
||||||
dbconf = config.getConfig()['database']
|
dbconf = config.getConfig()['database']
|
||||||
DbManager(dbconf)
|
DbManager(dbconf)
|
||||||
|
if DbManager().getConnection():
|
||||||
|
db_con = True
|
||||||
|
user = UserManager()
|
||||||
|
business_model = BusinessModel()
|
||||||
|
address_model = AddressModel()
|
||||||
|
business_type = BTypeModel()
|
||||||
|
contact_model = ContactModel()
|
||||||
|
publishContext()
|
||||||
bad_config = False
|
bad_config = False
|
||||||
user = UserManager()
|
|
||||||
business_model = BusinessModel()
|
|
||||||
address_model = AddressModel()
|
|
||||||
business_type = BTypeModel()
|
|
||||||
contact_model = ContactModel()
|
|
||||||
|
|
||||||
publishContext()
|
|
||||||
|
|
||||||
def publishContext():
|
def publishContext():
|
||||||
# print(f"In {__file__} file, publishContext()")
|
# print(f"In {__file__} file, publishContext()")
|
||||||
@@ -79,8 +80,6 @@ if __name__ == "__main__":
|
|||||||
config.configurationReady.connect(initializeProgram)
|
config.configurationReady.connect(initializeProgram)
|
||||||
else:
|
else:
|
||||||
initializeProgram()
|
initializeProgram()
|
||||||
if DbManager().getConnection():
|
|
||||||
db_con = True
|
|
||||||
|
|
||||||
|
|
||||||
engine.rootContext().setContextProperty("bad_config", bad_config) # print(f"Fehler: {i}")
|
engine.rootContext().setContextProperty("bad_config", bad_config) # print(f"Fehler: {i}")
|
||||||
|
|||||||
9
requirements.txt
Normal file
9
requirements.txt
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
PySide6
|
||||||
|
platformdirs
|
||||||
|
pycryptodome
|
||||||
|
psutil
|
||||||
|
toml
|
||||||
|
mariadb
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user