Skip to content

Commit

Permalink
Poll supervisor job state when creating or restoring a backup (#136891)
Browse files Browse the repository at this point in the history
* Poll supervisor job state when creating or restoring a backup

* Update tests

* Add tests for create and restore jobs finishing early
  • Loading branch information
emontnemery authored and bramkragten committed Jan 30, 2025
1 parent 8babdc0 commit 0764aca
Show file tree
Hide file tree
Showing 2 changed files with 136 additions and 52 deletions.
8 changes: 5 additions & 3 deletions homeassistant/components/hassio/backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,9 @@ def on_job_progress(data: Mapping[str, Any]) -> None:
backup_id = data.get("reference")
backup_complete.set()

unsub = self._async_listen_job_events(backup.job_id, on_job_progress)
try:
unsub = self._async_listen_job_events(backup.job_id, on_job_progress)
await self._get_job_state(backup.job_id, on_job_progress)
await backup_complete.wait()
finally:
unsub()
Expand Down Expand Up @@ -506,12 +507,13 @@ async def async_restore_backup(

@callback
def on_job_progress(data: Mapping[str, Any]) -> None:
"""Handle backup progress."""
"""Handle backup restore progress."""
if data.get("done") is True:
restore_complete.set()

unsub = self._async_listen_job_events(job.job_id, on_job_progress)
try:
unsub = self._async_listen_job_events(job.job_id, on_job_progress)
await self._get_job_state(job.job_id, on_job_progress)
await restore_complete.wait()
finally:
unsub()
Expand Down
Loading

0 comments on commit 0764aca

Please sign in to comment.