@@ -28,11 +28,12 @@ def __init__(self, *args, **kwargs):
28
28
def configure (self , config_dict ):
29
29
self .host = config_dict .get ('mysql' ).get ('host' , 'localhost' )
30
30
self .port = config_dict .get ('mysql' ).get ('port' , 3306 )
31
+ self .socket = config_dict .get ('mysql' ).get ('socket' , None )
31
32
32
33
self .username = config_dict .get ('mysql' ).get ('username' , 'root' )
33
34
self .password = config_dict .get ('mysql' ).get ('password' , '' )
34
35
35
- self .max_reconnect = int (config_dict .get ('mysql' ).get ('max_reconnect' , 30 ))
36
+ self .max_reconnect = int (config_dict .get ('mysql' ).get ('max_reconnect' , 5 ))
36
37
self .max_recovery = int (config_dict .get ('mysql' ).get ('max_recovery' , 10 ))
37
38
38
39
#Set the stats checks for MySQL
@@ -56,17 +57,21 @@ def configure(self, config_dict):
56
57
def setup_connection (self ):
57
58
connection_attempt = 0
58
59
59
- while self .max_reconnect == 0 or connection_attempt <= self .max_reconnect :
60
- try :
61
- self .connection = mdb .connect (host = self .host , user = self .username , port = self .port , passwd = self .password )
62
- return self .connection
63
- except Exception :
64
- pass
65
-
66
- # If we got here, connection failed
67
- connection_attempt += 1
68
- time .sleep (self .reconnect_delay )
69
- print ('Attempting reconnect #{0}...' .format (connection_attempt ))
60
+ while self .max_reconnect == 0 or connection_attempt < self .max_reconnect :
61
+ try :
62
+ if self .socket :
63
+ self .connection = mdb .connect (user = self .username , unix_socket = self .socket , passwd = self .password )
64
+ else :
65
+ self .connection = mdb .connect (host = self .host , user = self .username , port = self .port , passwd = self .password )
66
+
67
+ return self .connection
68
+ except Exception :
69
+ pass
70
+
71
+ # If we got here, connection failed
72
+ connection_attempt += 1
73
+ print ('Attempting reconnect #{0}...' .format (connection_attempt ))
74
+ time .sleep (self .reconnect_delay )
70
75
71
76
# If we get out of the while loop, we've passed max_reconnect
72
77
raise ThreadMySQLMaxReconnectException
0 commit comments