diff --git a/homeassistant/components/recorder/__init__.py b/homeassistant/components/recorder/__init__.py index 50c522f0e97..c8feb3fbe9b 100644 --- a/homeassistant/components/recorder/__init__.py +++ b/homeassistant/components/recorder/__init__.py @@ -86,7 +86,7 @@ from .util import ( end_incomplete_runs, is_second_sunday, move_away_broken_database, - perodic_db_cleanups, + periodic_db_cleanups, session_scope, setup_connection_for_dialect, validate_or_move_away_sqlite_database, @@ -448,7 +448,7 @@ class PurgeTask(RecorderTask): # We always need to do the db cleanups after a purge # is finished to ensure the WAL checkpoint and other # tasks happen after a vacuum. - perodic_db_cleanups(instance) + periodic_db_cleanups(instance) return # Schedule a new purge task if this one didn't finish instance.queue.put(PurgeTask(self.purge_before, self.repack, self.apply_filter)) @@ -474,7 +474,7 @@ class PerodicCleanupTask(RecorderTask): def run(self, instance: Recorder) -> None: """Handle the task.""" - perodic_db_cleanups(instance) + periodic_db_cleanups(instance) @dataclass @@ -891,7 +891,7 @@ class Recorder(threading.Thread): def async_nightly_tasks(self, now: datetime) -> None: """Trigger the purge.""" if self.auto_purge: - # Purge will schedule the perodic cleanups + # Purge will schedule the periodic cleanups # after it completes to ensure it does not happen # until after the database is vacuumed repack = self.auto_repack and is_second_sunday(now) @@ -948,7 +948,7 @@ class Recorder(threading.Thread): self.hass, self._async_keep_alive, timedelta(seconds=KEEPALIVE_TIME) ) - # If the commit interval is not 0, we need commit periodicly + # If the commit interval is not 0, we need to commit periodically if self.commit_interval: self._commit_listener = async_track_time_interval( self.hass, self._async_commit, timedelta(seconds=self.commit_interval) diff --git a/homeassistant/components/recorder/util.py b/homeassistant/components/recorder/util.py index ff862e6a6b0..b67f4c6d558 100644 --- a/homeassistant/components/recorder/util.py +++ b/homeassistant/components/recorder/util.py @@ -464,8 +464,8 @@ def retryable_database_job(description: str) -> Callable: return decorator -def perodic_db_cleanups(instance: Recorder) -> None: - """Run any database cleanups that need to happen perodiclly. +def periodic_db_cleanups(instance: Recorder) -> None: + """Run any database cleanups that need to happen periodically. These cleanups will happen nightly or after any purge. """ diff --git a/tests/components/recorder/test_init.py b/tests/components/recorder/test_init.py index 43a30932ac5..8272ba79a18 100644 --- a/tests/components/recorder/test_init.py +++ b/tests/components/recorder/test_init.py @@ -666,37 +666,37 @@ def test_auto_purge(hass_recorder): with patch( "homeassistant.components.recorder.purge.purge_old_data", return_value=True ) as purge_old_data, patch( - "homeassistant.components.recorder.perodic_db_cleanups" - ) as perodic_db_cleanups: + "homeassistant.components.recorder.periodic_db_cleanups" + ) as periodic_db_cleanups: # Advance one day, and the purge task should run test_time = test_time + timedelta(days=1) run_tasks_at_time(hass, test_time) assert len(purge_old_data.mock_calls) == 1 - assert len(perodic_db_cleanups.mock_calls) == 1 + assert len(periodic_db_cleanups.mock_calls) == 1 purge_old_data.reset_mock() - perodic_db_cleanups.reset_mock() + periodic_db_cleanups.reset_mock() # Advance one day, and the purge task should run again test_time = test_time + timedelta(days=1) run_tasks_at_time(hass, test_time) assert len(purge_old_data.mock_calls) == 1 - assert len(perodic_db_cleanups.mock_calls) == 1 + assert len(periodic_db_cleanups.mock_calls) == 1 purge_old_data.reset_mock() - perodic_db_cleanups.reset_mock() + periodic_db_cleanups.reset_mock() # Advance less than one full day. The alarm should not yet fire. test_time = test_time + timedelta(hours=23) run_tasks_at_time(hass, test_time) assert len(purge_old_data.mock_calls) == 0 - assert len(perodic_db_cleanups.mock_calls) == 0 + assert len(periodic_db_cleanups.mock_calls) == 0 # Advance to the next day and fire the alarm again test_time = test_time + timedelta(hours=1) run_tasks_at_time(hass, test_time) assert len(purge_old_data.mock_calls) == 1 - assert len(perodic_db_cleanups.mock_calls) == 1 + assert len(periodic_db_cleanups.mock_calls) == 1 dt_util.set_default_time_zone(original_tz) @@ -726,15 +726,15 @@ def test_auto_purge_auto_repack_on_second_sunday(hass_recorder): ), patch( "homeassistant.components.recorder.purge.purge_old_data", return_value=True ) as purge_old_data, patch( - "homeassistant.components.recorder.perodic_db_cleanups" - ) as perodic_db_cleanups: + "homeassistant.components.recorder.periodic_db_cleanups" + ) as periodic_db_cleanups: # Advance one day, and the purge task should run test_time = test_time + timedelta(days=1) run_tasks_at_time(hass, test_time) assert len(purge_old_data.mock_calls) == 1 args, _ = purge_old_data.call_args_list[0] assert args[2] is True # repack - assert len(perodic_db_cleanups.mock_calls) == 1 + assert len(periodic_db_cleanups.mock_calls) == 1 dt_util.set_default_time_zone(original_tz) @@ -764,15 +764,15 @@ def test_auto_purge_auto_repack_disabled_on_second_sunday(hass_recorder): ), patch( "homeassistant.components.recorder.purge.purge_old_data", return_value=True ) as purge_old_data, patch( - "homeassistant.components.recorder.perodic_db_cleanups" - ) as perodic_db_cleanups: + "homeassistant.components.recorder.periodic_db_cleanups" + ) as periodic_db_cleanups: # Advance one day, and the purge task should run test_time = test_time + timedelta(days=1) run_tasks_at_time(hass, test_time) assert len(purge_old_data.mock_calls) == 1 args, _ = purge_old_data.call_args_list[0] assert args[2] is False # repack - assert len(perodic_db_cleanups.mock_calls) == 1 + assert len(periodic_db_cleanups.mock_calls) == 1 dt_util.set_default_time_zone(original_tz) @@ -802,15 +802,15 @@ def test_auto_purge_no_auto_repack_on_not_second_sunday(hass_recorder): ), patch( "homeassistant.components.recorder.purge.purge_old_data", return_value=True ) as purge_old_data, patch( - "homeassistant.components.recorder.perodic_db_cleanups" - ) as perodic_db_cleanups: + "homeassistant.components.recorder.periodic_db_cleanups" + ) as periodic_db_cleanups: # Advance one day, and the purge task should run test_time = test_time + timedelta(days=1) run_tasks_at_time(hass, test_time) assert len(purge_old_data.mock_calls) == 1 args, _ = purge_old_data.call_args_list[0] assert args[2] is False # repack - assert len(perodic_db_cleanups.mock_calls) == 1 + assert len(periodic_db_cleanups.mock_calls) == 1 dt_util.set_default_time_zone(original_tz) @@ -837,16 +837,16 @@ def test_auto_purge_disabled(hass_recorder): with patch( "homeassistant.components.recorder.purge.purge_old_data", return_value=True ) as purge_old_data, patch( - "homeassistant.components.recorder.perodic_db_cleanups" - ) as perodic_db_cleanups: + "homeassistant.components.recorder.periodic_db_cleanups" + ) as periodic_db_cleanups: # Advance one day, and the purge task should run test_time = test_time + timedelta(days=1) run_tasks_at_time(hass, test_time) assert len(purge_old_data.mock_calls) == 0 - assert len(perodic_db_cleanups.mock_calls) == 1 + assert len(periodic_db_cleanups.mock_calls) == 1 purge_old_data.reset_mock() - perodic_db_cleanups.reset_mock() + periodic_db_cleanups.reset_mock() dt_util.set_default_time_zone(original_tz) diff --git a/tests/components/recorder/test_util.py b/tests/components/recorder/test_util.py index 9372740c9bb..5ecf6f892ad 100644 --- a/tests/components/recorder/test_util.py +++ b/tests/components/recorder/test_util.py @@ -550,11 +550,11 @@ def test_end_incomplete_runs(hass_recorder, caplog): assert "Ended unfinished session" in caplog.text -def test_perodic_db_cleanups(hass_recorder): - """Test perodic db cleanups.""" +def test_periodic_db_cleanups(hass_recorder): + """Test periodic db cleanups.""" hass = hass_recorder() with patch.object(hass.data[DATA_INSTANCE].engine, "connect") as connect_mock: - util.perodic_db_cleanups(hass.data[DATA_INSTANCE]) + util.periodic_db_cleanups(hass.data[DATA_INSTANCE]) text_obj = connect_mock.return_value.__enter__.return_value.execute.mock_calls[0][ 1