Added MariaDB connection timout
* Prevents waiting 1-2 minutes for it to fail if the server can't be reached * Connection attempt is made once per _connect() call
This commit is contained in:
parent
cf75348c2c
commit
8a4c2c059c
1 changed files with 13 additions and 20 deletions
|
|
@ -52,26 +52,19 @@ class osTicket(): # pylint: disable=invalid-name
|
||||||
return
|
return
|
||||||
|
|
||||||
# Connect to database
|
# Connect to database
|
||||||
for i in range(3):
|
try:
|
||||||
i += 1
|
self.db_connection = mariadb.connect(
|
||||||
try:
|
host=SQL['Host'],
|
||||||
self.db_connection = mariadb.connect(
|
port=SQL['Port'],
|
||||||
host=SQL['Host'],
|
database=SQL['DB'],
|
||||||
port=SQL['Port'],
|
user=SQL['User'],
|
||||||
database=SQL['DB'],
|
password=SQL['Pass'],
|
||||||
user=SQL['User'],
|
connection_timeout=5,
|
||||||
password=SQL['Pass'],
|
)
|
||||||
)
|
self.db_cursor = self.db_connection.cursor()
|
||||||
self.db_cursor = self.db_connection.cursor()
|
except mariadb.errors.Error:
|
||||||
except mariadb.errors.InterfaceError:
|
# Assuming network issue or bad creds
|
||||||
# Network issue? try again
|
pass
|
||||||
std.sleep(2)
|
|
||||||
except mariadb.errors.Error:
|
|
||||||
# Bad creds or other SQL error, bail
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
# Connection established
|
|
||||||
break
|
|
||||||
|
|
||||||
# Raise exception if necessary
|
# Raise exception if necessary
|
||||||
if self.db_cursor is None:
|
if self.db_cursor is None:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue