Small cleanup to be more robust (#1876)

This commit is contained in:
Pascal Vizeli 2020-08-07 21:43:03 +02:00 committed by GitHub
parent d6d3bf0583
commit 311c981d1a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 3 deletions

View File

@ -5,6 +5,7 @@ import asyncio
from typing import TYPE_CHECKING, Any, Callable, Coroutine, Optional, TypeVar
import aiohttp
import sentry_sdk
from .config import CoreConfig
from .const import UpdateChannels
@ -612,3 +613,7 @@ class CoreSysAttributes:
def sys_create_task(self, coroutine: Coroutine) -> asyncio.Task:
"""Create an async task."""
return self.sys_loop.create_task(coroutine)
def sys_capture_exception(self, err: Exception) -> None:
"""Capture a exception."""
sentry_sdk.capture_exception(err)

View File

@ -217,11 +217,11 @@ class DockerInterface(CoreSysAttributes):
except docker.errors.DockerException:
raise DockerAPIError() from None
_LOGGER.info("Start %s", self.image)
_LOGGER.info("Start %s", self.name)
try:
docker_container.start()
except docker.errors.DockerException as err:
_LOGGER.error("Can't start %s: %s", self.image, err)
_LOGGER.error("Can't start %s: %s", self.name, err)
raise DockerAPIError() from None
@process_lock

View File

@ -268,6 +268,8 @@ class HomeAssistant(JsonConfig, CoreSysAttributes):
except DockerAPIError:
_LOGGER.warning("Fails install landingpage, retry after 30sec")
await asyncio.sleep(30)
except Exception as err: # pylint: disable=broad-except
self.sys_capture_exception(err)
else:
self.version = self.instance.version
self.image = self.sys_updater.image_homeassistant
@ -290,11 +292,16 @@ class HomeAssistant(JsonConfig, CoreSysAttributes):
tag = self.latest_version
if tag:
with suppress(DockerAPIError):
try:
await self.instance.update(
tag, image=self.sys_updater.image_homeassistant
)
break
except DockerAPIError:
pass
except Exception as err: # pylint: disable=broad-except
self.sys_capture_exception(err)
_LOGGER.warning("Error on install Home Assistant. Retry in 30sec")
await asyncio.sleep(30)
@ -596,6 +603,7 @@ class HomeAssistant(JsonConfig, CoreSysAttributes):
# Skip landingpage
if version == LANDINGPAGE:
return
_LOGGER.info("Wait until Home Assistant is ready")
# Manage timeouts
timeout: bool = True