Commit b61ee7f1 authored by Julien Muchembled's avatar Julien Muchembled

mysql: do not flood logs when retrying to connect non-stop

parent ed966e80
...@@ -80,14 +80,21 @@ class MySQLDatabaseManager(DatabaseManager): ...@@ -80,14 +80,21 @@ class MySQLDatabaseManager(DatabaseManager):
timeout_at = None timeout_at = None
else: else:
timeout_at = time.time() + self._wait timeout_at = time.time() + self._wait
last = None
while True: while True:
try: try:
self.conn = MySQLdb.connect(**kwd) self.conn = MySQLdb.connect(**kwd)
break break
except Exception: except Exception as e:
if timeout_at is not None and time.time() >= timeout_at: if None is not timeout_at <= time.time():
raise raise
logging.exception('Connection to MySQL failed, retrying.') e = str(e)
if last == e:
log = logging.debug
else:
last = e
log = logging.exception
log('Connection to MySQL failed, retrying.')
time.sleep(1) time.sleep(1)
self._active = 0 self._active = 0
self._config = {} self._config = {}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment