Fix recorder stop on SQLite vacuuming error (#10405)

* Fix recorder stop on SQLite vacuuming error

* Move import to function
This commit is contained in:
Milan V 2017-11-08 14:43:15 +01:00 committed by Pascal Vizeli
parent 2e5b1e76ef
commit 2f0920e4fb

View File

@ -28,5 +28,10 @@ def purge_old_data(instance, purge_days):
# Execute sqlite vacuum command to free up space on disk
_LOGGER.debug("DB engine driver: %s", instance.engine.driver)
if instance.engine.driver == 'pysqlite':
from sqlalchemy import exc
_LOGGER.info("Vacuuming SQLite to free space")
instance.engine.execute("VACUUM")
try:
instance.engine.execute("VACUUM")
except exc.OperationalError as err:
_LOGGER.error("Error vacuuming SQLite: %s.", err)