Disconnect Handling to SQL

This commit is contained in:
rusal 2023-07-15 08:38:12 -04:00
parent af2c05bdb8
commit f93f8613a3
3 changed files with 29 additions and 31 deletions

1
.gitignore vendored
View File

@ -3,6 +3,7 @@
#ignore IDE settings
*.idea*
*.vscode*
#setup
build/*

View File

@ -43,25 +43,22 @@ def db_inputs(connection_type):
def create_connection():
"""
a function to create connections to db, it retries 100 times if connection returned an error
a function to create connections to db with pessimistic approach
Returns:
connection if success otherwise False
"""
try:
for _ in range(0, 100):
try:
db_engine = create_engine(
db_inputs(DB),
connect_args={
'check_same_thread': False
}
},
pool_pre_ping=True
)
Session = sessionmaker(bind=db_engine)
session = Session()
return session
except Exception:
time.sleep(0.1)
except Exception:
warn(messages("database_connect_fail"))
return False

View File

@ -9,7 +9,7 @@ texttable==1.6.7
PySocks==1.7.1 # library_name=socks # module name is not equal to socks name; this is required to be checked on startup
pyOpenSSL==23.2.0 # library_name=OpenSSL
flask==2.3.2
SQLAlchemy>=1.3.0 # library_name=sqlalchemy
SQLAlchemy>=1.4.43 # library_name=sqlalchemy
py3DNS==3.2.1 # library_name=DNS
numpy==1.24.3
terminable_thread==0.7.1