Skip to content

Commit

Permalink
Backup and restore track progress in job (home-assistant#4503)
Browse files Browse the repository at this point in the history
* Backup and restore track progress in job

* Change to stage only updates and fix tests

* Leave HA alone if it wasn't restored

* skip check HA stage message when we don't check

* Change to helper to get current job

* Fix tests

* Mark jobs as internal to skip notifying HA
  • Loading branch information
mdegat01 authored and adeepn committed Aug 31, 2023
1 parent 92d4d78 commit 26a4118
Show file tree
Hide file tree
Showing 27 changed files with 892 additions and 215 deletions.
12 changes: 4 additions & 8 deletions supervisor/addons/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,7 @@ async def shutdown(self, stage: AddonStartup) -> None:
)
async def install(self, slug: str) -> None:
"""Install an add-on."""
if job := self.sys_jobs.get_job():
job.reference = slug
self.sys_jobs.current.reference = slug

if slug in self.local:
raise AddonsError(f"Add-on {slug} is already installed", _LOGGER.warning)
Expand Down Expand Up @@ -263,8 +262,7 @@ async def update(
Returns a coroutine that completes when addon has state 'started' (see addon.start)
if addon is started after update. Else nothing is returned.
"""
if job := self.sys_jobs.get_job():
job.reference = slug
self.sys_jobs.current.reference = slug

if slug not in self.local:
raise AddonsError(f"Add-on {slug} is not installed", _LOGGER.error)
Expand Down Expand Up @@ -329,8 +327,7 @@ async def rebuild(self, slug: str) -> Awaitable[None] | None:
Returns a coroutine that completes when addon has state 'started' (see addon.start)
if addon is started after rebuild. Else nothing is returned.
"""
if job := self.sys_jobs.get_job():
job.reference = slug
self.sys_jobs.current.reference = slug

if slug not in self.local:
raise AddonsError(f"Add-on {slug} is not installed", _LOGGER.error)
Expand Down Expand Up @@ -387,8 +384,7 @@ async def restore(
Returns a coroutine that completes when addon has state 'started' (see addon.start)
if addon is started after restore. Else nothing is returned.
"""
if job := self.sys_jobs.get_job():
job.reference = slug
self.sys_jobs.current.reference = slug

if slug not in self.local:
_LOGGER.debug("Add-on %s is not local available for restore", slug)
Expand Down
30 changes: 28 additions & 2 deletions supervisor/backups/const.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,37 @@
"""Backup consts."""
from enum import Enum
from enum import StrEnum

BUF_SIZE = 2**20 * 4 # 4MB


class BackupType(str, Enum):
class BackupType(StrEnum):
"""Backup type enum."""

FULL = "full"
PARTIAL = "partial"


class BackupJobStage(StrEnum):
"""Backup job stage enum."""

ADDON_REPOSITORIES = "addon_repositories"
ADDONS = "addons"
DOCKER_CONFIG = "docker_config"
FINISHING_FILE = "finishing_file"
FOLDERS = "folders"
HOME_ASSISTANT = "home_assistant"
AWAIT_ADDON_RESTARTS = "await_addon_restarts"


class RestoreJobStage(StrEnum):
"""Restore job stage enum."""

ADDON_REPOSITORIES = "addon_repositories"
ADDONS = "addons"
AWAIT_ADDON_RESTARTS = "await_addon_restarts"
AWAIT_HOME_ASSISTANT_RESTART = "await_home_assistant_restart"
CHECK_HOME_ASSISTANT = "check_home_assistant"
DOCKER_CONFIG = "docker_config"
FOLDERS = "folders"
HOME_ASSISTANT = "home_assistant"
REMOVE_DELTA_ADDONS = "remove_delta_addons"
Loading

0 comments on commit 26a4118

Please sign in to comment.