from base64 import b64encode
from dataclasses import dataclass, InitVar
from getpass import getuser
+from re import search as re_search, IGNORECASE as re_IGNORECASE
from threading import Thread
from time import sleep
from typing import (Any, Callable, Collection, Generic, Iterable, Iterator,
_NAMES_DESIRED_SERVER_CAPS = ('sasl',)
+_DISCONNECT_MSG_REGEXES_TO_RETRY_ON = (
+ r'^Closing Link: \(Connection timed out\)$',
+ r'^Closing Link: \(Ping timeout: [0-9]+ seconds\)$'
+)
class SendFail(Exception):
def consider_retry(self) -> None:
'Interpret .db.connection_state, on triggers set retry connect.'
- if self.db.connection_state.endswith('timed out)')\
- and not self._retry_connect_in_s > 0:
- self._retry_connect_in_s = 1
+ if not self._retry_connect_in_s > 0:
+ for _ in [
+ re for re in _DISCONNECT_MSG_REGEXES_TO_RETRY_ON
+ if re_search(re, self.db.connection_state, re_IGNORECASE)]:
+ self._retry_connect_in_s = 1
+ break
def close(self) -> None:
'Close connection, wipe memory of its states, reconnect if indicated.'