Fix recorder hanging at start (#75627)

This commit is contained in:
J. Nick Koston 2022-07-22 12:37:25 -05:00 committed by GitHub
parent c05905ebda
commit 20b6c4c48e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 12 deletions

View file

@ -436,7 +436,7 @@ class Recorder(threading.Thread):
self.async_db_connected.set_result(True)
@callback
def async_set_recorder_ready(self) -> None:
def async_set_db_ready(self) -> None:
"""Database live and ready for use.
Called after non-live migration steps are finished.
@ -577,14 +577,19 @@ class Recorder(threading.Thread):
self.hass.add_job(self.async_connection_success)
# If shutdown happened before Home Assistant finished starting
if self._wait_startup_or_shutdown() is SHUTDOWN_TASK:
self.migration_in_progress = False
# Make sure we cleanly close the run if
# we restart before startup finishes
self._shutdown()
self.hass.add_job(self.async_set_recorder_ready)
return
if self.migration_is_live or schema_is_current:
# If the migrate is live or the schema is current, we need to
# wait for startup to complete. If its not live, we need to continue
# on.
self.hass.add_job(self.async_set_db_ready)
# If shutdown happened before Home Assistant finished starting
if self._wait_startup_or_shutdown() is SHUTDOWN_TASK:
self.migration_in_progress = False
# Make sure we cleanly close the run if
# we restart before startup finishes
self._shutdown()
self.hass.add_job(self.async_set_db_ready)
return
# We wait to start the migration until startup has finished
# since it can be cpu intensive and we do not want it to compete
@ -604,11 +609,11 @@ class Recorder(threading.Thread):
"Database Migration Failed",
"recorder_database_migration",
)
self.hass.add_job(self.async_set_recorder_ready)
self.hass.add_job(self.async_set_db_ready)
self._shutdown()
return
self.hass.add_job(self.async_set_recorder_ready)
self.hass.add_job(self.async_set_db_ready)
_LOGGER.debug("Recorder processing the queue")
self.hass.add_job(self._async_set_recorder_ready_migration_done)

View file

@ -99,7 +99,7 @@ def migrate_schema(
if live_migration(version) and not db_ready:
db_ready = True
instance.migration_is_live = True
hass.add_job(instance.async_set_recorder_ready)
hass.add_job(instance.async_set_db_ready)
new_version = version + 1
_LOGGER.info("Upgrading recorder db schema to version %s", new_version)
_apply_update(hass, engine, session_maker, new_version, current_version)