Make startup more stable (#2167)

This commit is contained in:
Pascal Vizeli 2020-10-23 16:48:03 +02:00 committed by GitHub
parent c423e9cf8e
commit 042bdcdf37
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 47 additions and 46 deletions

View File

@ -79,6 +79,8 @@ class RestAPI(CoreSysAttributes):
self._register_snapshots() self._register_snapshots()
self._register_supervisor() self._register_supervisor()
await self.start()
def _register_host(self) -> None: def _register_host(self) -> None:
"""Register hostcontrol functions.""" """Register hostcontrol functions."""
api_host = APIHost() api_host = APIHost()

View File

@ -2,7 +2,7 @@
import asyncio import asyncio
from contextlib import suppress from contextlib import suppress
import logging import logging
from typing import Optional from typing import Awaitable, List, Optional
import async_timeout import async_timeout
@ -112,51 +112,49 @@ class Core(CoreSysAttributes):
"""Start setting up supervisor orchestration.""" """Start setting up supervisor orchestration."""
self.state = CoreState.SETUP self.state = CoreState.SETUP
setup_loads: List[Awaitable[None]] = [
# rest api views # rest api views
await self.sys_api.load() self.sys_api.load(),
await self.sys_api.start()
# Load DBus # Load DBus
await self.sys_dbus.load() self.sys_dbus.load(),
# Load Host # Load Host
await self.sys_host.load() self.sys_host.load(),
# Load Plugins container # Load Plugins container
await self.sys_plugins.load() self.sys_plugins.load(),
# load last available data # load last available data
await self.sys_updater.load() self.sys_updater.load(),
# Load Home Assistant # Load Home Assistant
await self.sys_homeassistant.load() self.sys_homeassistant.load(),
# Load CPU/Arch # Load CPU/Arch
await self.sys_arch.load() self.sys_arch.load(),
# Load HassOS # Load HassOS
await self.sys_hassos.load() self.sys_hassos.load(),
# Load Stores # Load Stores
await self.sys_store.load() self.sys_store.load(),
# Load Add-ons # Load Add-ons
await self.sys_addons.load() self.sys_addons.load(),
# load last available data # load last available data
await self.sys_snapshots.load() self.sys_snapshots.load(),
# load services # load services
await self.sys_services.load() self.sys_services.load(),
# Load discovery # Load discovery
await self.sys_discovery.load() self.sys_discovery.load(),
# Load ingress # Load ingress
await self.sys_ingress.load() self.sys_ingress.load(),
# Load Resoulution # Load Resoulution
await self.sys_resolution.load() self.sys_resolution.load(),
]
# Execute each load task in secure context
for setup_task in setup_loads:
try:
await setup_task
except Exception as err: # pylint: disable=broad-except
_LOGGER.critical(
"Fatal error happening on load Task %s: %s", setup_task, err
)
self.healthy = False
self.sys_capture_exception(err)
# Check supported OS # Check supported OS
if not self.sys_hassos.available: if not self.sys_hassos.available:

View File

@ -1,6 +1,6 @@
"""Common test functions.""" """Common test functions."""
from pathlib import Path from pathlib import Path
from unittest.mock import MagicMock, PropertyMock, patch from unittest.mock import AsyncMock, MagicMock, PropertyMock, patch
from uuid import uuid4 from uuid import uuid4
from aiohttp import web from aiohttp import web
@ -148,6 +148,7 @@ async def api_client(aiohttp_client, coresys: CoreSys):
"""Fixture for RestAPI client.""" """Fixture for RestAPI client."""
api = RestAPI(coresys) api = RestAPI(coresys)
api.webapp = web.Application() api.webapp = web.Application()
api.start = AsyncMock()
await api.load() await api.load()
yield await aiohttp_client(api.webapp) yield await aiohttp_client(api.webapp)