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:
2Shirt 2020-01-24 17:53:01 -07:00
parent cf75348c2c
commit 8a4c2c059c
Signed by: 2Shirt
GPG key ID: 152FAC923B0E132C

View file

@ -52,8 +52,6 @@ class osTicket(): # pylint: disable=invalid-name
return return
# Connect to database # Connect to database
for i in range(3):
i += 1
try: try:
self.db_connection = mariadb.connect( self.db_connection = mariadb.connect(
host=SQL['Host'], host=SQL['Host'],
@ -61,17 +59,12 @@ class osTicket(): # pylint: disable=invalid-name
database=SQL['DB'], database=SQL['DB'],
user=SQL['User'], user=SQL['User'],
password=SQL['Pass'], password=SQL['Pass'],
connection_timeout=5,
) )
self.db_cursor = self.db_connection.cursor() self.db_cursor = self.db_connection.cursor()
except mariadb.errors.InterfaceError:
# Network issue? try again
std.sleep(2)
except mariadb.errors.Error: except mariadb.errors.Error:
# Bad creds or other SQL error, bail # Assuming network issue or bad creds
break pass
else:
# Connection established
break
# Raise exception if necessary # Raise exception if necessary
if self.db_cursor is None: if self.db_cursor is None: