Fix spelling of periodic in recorder (#69658)

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
J. Nick Koston 2022-04-07 23:37:02 -10:00 committed by GitHub
parent 89dd199ac2
commit 72fffde77a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 31 additions and 31 deletions

View File

@ -86,7 +86,7 @@ from .util import (
end_incomplete_runs, end_incomplete_runs,
is_second_sunday, is_second_sunday,
move_away_broken_database, move_away_broken_database,
perodic_db_cleanups, periodic_db_cleanups,
session_scope, session_scope,
setup_connection_for_dialect, setup_connection_for_dialect,
validate_or_move_away_sqlite_database, validate_or_move_away_sqlite_database,
@ -448,7 +448,7 @@ class PurgeTask(RecorderTask):
# We always need to do the db cleanups after a purge # We always need to do the db cleanups after a purge
# is finished to ensure the WAL checkpoint and other # is finished to ensure the WAL checkpoint and other
# tasks happen after a vacuum. # tasks happen after a vacuum.
perodic_db_cleanups(instance) periodic_db_cleanups(instance)
return return
# Schedule a new purge task if this one didn't finish # Schedule a new purge task if this one didn't finish
instance.queue.put(PurgeTask(self.purge_before, self.repack, self.apply_filter)) 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: def run(self, instance: Recorder) -> None:
"""Handle the task.""" """Handle the task."""
perodic_db_cleanups(instance) periodic_db_cleanups(instance)
@dataclass @dataclass
@ -891,7 +891,7 @@ class Recorder(threading.Thread):
def async_nightly_tasks(self, now: datetime) -> None: def async_nightly_tasks(self, now: datetime) -> None:
"""Trigger the purge.""" """Trigger the purge."""
if self.auto_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 # after it completes to ensure it does not happen
# until after the database is vacuumed # until after the database is vacuumed
repack = self.auto_repack and is_second_sunday(now) 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) 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: if self.commit_interval:
self._commit_listener = async_track_time_interval( self._commit_listener = async_track_time_interval(
self.hass, self._async_commit, timedelta(seconds=self.commit_interval) self.hass, self._async_commit, timedelta(seconds=self.commit_interval)

View File

@ -464,8 +464,8 @@ def retryable_database_job(description: str) -> Callable:
return decorator return decorator
def perodic_db_cleanups(instance: Recorder) -> None: def periodic_db_cleanups(instance: Recorder) -> None:
"""Run any database cleanups that need to happen perodiclly. """Run any database cleanups that need to happen periodically.
These cleanups will happen nightly or after any purge. These cleanups will happen nightly or after any purge.
""" """

View File

@ -666,37 +666,37 @@ def test_auto_purge(hass_recorder):
with patch( with patch(
"homeassistant.components.recorder.purge.purge_old_data", return_value=True "homeassistant.components.recorder.purge.purge_old_data", return_value=True
) as purge_old_data, patch( ) as purge_old_data, patch(
"homeassistant.components.recorder.perodic_db_cleanups" "homeassistant.components.recorder.periodic_db_cleanups"
) as perodic_db_cleanups: ) as periodic_db_cleanups:
# Advance one day, and the purge task should run # Advance one day, and the purge task should run
test_time = test_time + timedelta(days=1) test_time = test_time + timedelta(days=1)
run_tasks_at_time(hass, test_time) run_tasks_at_time(hass, test_time)
assert len(purge_old_data.mock_calls) == 1 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() 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 # Advance one day, and the purge task should run again
test_time = test_time + timedelta(days=1) test_time = test_time + timedelta(days=1)
run_tasks_at_time(hass, test_time) run_tasks_at_time(hass, test_time)
assert len(purge_old_data.mock_calls) == 1 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() 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. # Advance less than one full day. The alarm should not yet fire.
test_time = test_time + timedelta(hours=23) test_time = test_time + timedelta(hours=23)
run_tasks_at_time(hass, test_time) run_tasks_at_time(hass, test_time)
assert len(purge_old_data.mock_calls) == 0 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 # Advance to the next day and fire the alarm again
test_time = test_time + timedelta(hours=1) test_time = test_time + timedelta(hours=1)
run_tasks_at_time(hass, test_time) run_tasks_at_time(hass, test_time)
assert len(purge_old_data.mock_calls) == 1 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) dt_util.set_default_time_zone(original_tz)
@ -726,15 +726,15 @@ def test_auto_purge_auto_repack_on_second_sunday(hass_recorder):
), patch( ), patch(
"homeassistant.components.recorder.purge.purge_old_data", return_value=True "homeassistant.components.recorder.purge.purge_old_data", return_value=True
) as purge_old_data, patch( ) as purge_old_data, patch(
"homeassistant.components.recorder.perodic_db_cleanups" "homeassistant.components.recorder.periodic_db_cleanups"
) as perodic_db_cleanups: ) as periodic_db_cleanups:
# Advance one day, and the purge task should run # Advance one day, and the purge task should run
test_time = test_time + timedelta(days=1) test_time = test_time + timedelta(days=1)
run_tasks_at_time(hass, test_time) run_tasks_at_time(hass, test_time)
assert len(purge_old_data.mock_calls) == 1 assert len(purge_old_data.mock_calls) == 1
args, _ = purge_old_data.call_args_list[0] args, _ = purge_old_data.call_args_list[0]
assert args[2] is True # repack 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) 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( ), patch(
"homeassistant.components.recorder.purge.purge_old_data", return_value=True "homeassistant.components.recorder.purge.purge_old_data", return_value=True
) as purge_old_data, patch( ) as purge_old_data, patch(
"homeassistant.components.recorder.perodic_db_cleanups" "homeassistant.components.recorder.periodic_db_cleanups"
) as perodic_db_cleanups: ) as periodic_db_cleanups:
# Advance one day, and the purge task should run # Advance one day, and the purge task should run
test_time = test_time + timedelta(days=1) test_time = test_time + timedelta(days=1)
run_tasks_at_time(hass, test_time) run_tasks_at_time(hass, test_time)
assert len(purge_old_data.mock_calls) == 1 assert len(purge_old_data.mock_calls) == 1
args, _ = purge_old_data.call_args_list[0] args, _ = purge_old_data.call_args_list[0]
assert args[2] is False # repack 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) 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( ), patch(
"homeassistant.components.recorder.purge.purge_old_data", return_value=True "homeassistant.components.recorder.purge.purge_old_data", return_value=True
) as purge_old_data, patch( ) as purge_old_data, patch(
"homeassistant.components.recorder.perodic_db_cleanups" "homeassistant.components.recorder.periodic_db_cleanups"
) as perodic_db_cleanups: ) as periodic_db_cleanups:
# Advance one day, and the purge task should run # Advance one day, and the purge task should run
test_time = test_time + timedelta(days=1) test_time = test_time + timedelta(days=1)
run_tasks_at_time(hass, test_time) run_tasks_at_time(hass, test_time)
assert len(purge_old_data.mock_calls) == 1 assert len(purge_old_data.mock_calls) == 1
args, _ = purge_old_data.call_args_list[0] args, _ = purge_old_data.call_args_list[0]
assert args[2] is False # repack 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) dt_util.set_default_time_zone(original_tz)
@ -837,16 +837,16 @@ def test_auto_purge_disabled(hass_recorder):
with patch( with patch(
"homeassistant.components.recorder.purge.purge_old_data", return_value=True "homeassistant.components.recorder.purge.purge_old_data", return_value=True
) as purge_old_data, patch( ) as purge_old_data, patch(
"homeassistant.components.recorder.perodic_db_cleanups" "homeassistant.components.recorder.periodic_db_cleanups"
) as perodic_db_cleanups: ) as periodic_db_cleanups:
# Advance one day, and the purge task should run # Advance one day, and the purge task should run
test_time = test_time + timedelta(days=1) test_time = test_time + timedelta(days=1)
run_tasks_at_time(hass, test_time) run_tasks_at_time(hass, test_time)
assert len(purge_old_data.mock_calls) == 0 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() purge_old_data.reset_mock()
perodic_db_cleanups.reset_mock() periodic_db_cleanups.reset_mock()
dt_util.set_default_time_zone(original_tz) dt_util.set_default_time_zone(original_tz)

View File

@ -550,11 +550,11 @@ def test_end_incomplete_runs(hass_recorder, caplog):
assert "Ended unfinished session" in caplog.text assert "Ended unfinished session" in caplog.text
def test_perodic_db_cleanups(hass_recorder): def test_periodic_db_cleanups(hass_recorder):
"""Test perodic db cleanups.""" """Test periodic db cleanups."""
hass = hass_recorder() hass = hass_recorder()
with patch.object(hass.data[DATA_INSTANCE].engine, "connect") as connect_mock: 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][ text_obj = connect_mock.return_value.__enter__.return_value.execute.mock_calls[0][
1 1