Move imports in recorder component (#27859)

* move imports to top-level in recorder init

* move imports to top-level in recorder migration

* move imports to top-level in recorder models

* move imports to top-level in recorder purge

* move imports to top-level in recorder util

* fix pylint
This commit is contained in:
Malte Franken authored and Paulus Schoutsen committed 2019-10-18 10:14:54 -07:00
1 parent e95b8035ed
commit 83a709b768
6 files changed
+27 -50

No files matched your search

+3 -5
View File
@@ -3,6 +3,8 @@ from contextlib import contextmanager
import logging
import time
from sqlalchemy.exc import OperationalError, SQLAlchemyError
from .const import DATA_INSTANCE
_LOGGER = logging.getLogger(__name__)
@@ -37,8 +39,6 @@ def session_scope(*, hass=None, session=None):
def commit(session, work):
"""Commit & retry work: Either a model or in a function."""
import sqlalchemy.exc
for _ in range(0, RETRIES):
try:
if callable(work):
@@ -47,7 +47,7 @@ def commit(session, work):
session.add(work)
session.commit()
return True
except sqlalchemy.exc.OperationalError as err:
except OperationalError as err:
_LOGGER.error("Error executing query: %s", err)
session.rollback()
time.sleep(QUERY_RETRY_WAIT)
@@ -59,8 +59,6 @@ def execute(qry):
This method also retries a few times in the case of stale connections.
"""
from sqlalchemy.exc import SQLAlchemyError
for tryno in range(0, RETRIES):
try:
timer_start = time.perf_counter()