mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Shorten recorder connection init (#6432)
* Wait up to 9 seconds * Set number of recorder retries to 8 * Do not sleep when reporting last connection error if no retries left * Make sure we clean up old engine if connection is retrying * Update __init__.py
This commit is contained in:
parent
2baa838ba7
commit
90ad54da7d
@ -43,8 +43,7 @@ DEFAULT_DB_FILE = 'home-assistant_v2.db'
|
||||
CONF_DB_URL = 'db_url'
|
||||
CONF_PURGE_DAYS = 'purge_days'
|
||||
|
||||
CONNECT_RETRY_WAIT = 10
|
||||
ERROR_QUERY = "Error during query: %s"
|
||||
CONNECT_RETRY_WAIT = 3
|
||||
|
||||
FILTER_SCHEMA = vol.Schema({
|
||||
vol.Optional(CONF_EXCLUDE, default={}): vol.Schema({
|
||||
@ -159,7 +158,9 @@ class Recorder(threading.Thread):
|
||||
tries = 1
|
||||
connected = False
|
||||
|
||||
while not connected and tries < 5:
|
||||
while not connected and tries <= 10:
|
||||
if tries != 1:
|
||||
time.sleep(CONNECT_RETRY_WAIT)
|
||||
try:
|
||||
self._setup_connection()
|
||||
migration.migrate_schema(self)
|
||||
@ -168,7 +169,6 @@ class Recorder(threading.Thread):
|
||||
except Exception as err: # pylint: disable=broad-except
|
||||
_LOGGER.error("Error during connection setup: %s (retrying "
|
||||
"in %s seconds)", err, CONNECT_RETRY_WAIT)
|
||||
time.sleep(CONNECT_RETRY_WAIT)
|
||||
tries += 1
|
||||
|
||||
if not connected:
|
||||
@ -303,6 +303,9 @@ class Recorder(threading.Thread):
|
||||
else:
|
||||
kwargs['echo'] = False
|
||||
|
||||
if self.engine is not None:
|
||||
self.engine.dispose()
|
||||
|
||||
self.engine = create_engine(self.db_url, **kwargs)
|
||||
models.Base.metadata.create_all(self.engine)
|
||||
self.get_session = scoped_session(sessionmaker(bind=self.engine))
|
||||
|
Loading…
x
Reference in New Issue
Block a user