From 115af4cadf45015f765eec29e4b63287b1efeb4a Mon Sep 17 00:00:00 2001 From: Pascal Vizeli Date: Thu, 25 Feb 2021 14:05:27 +0100 Subject: [PATCH] Optimize resolution checks / add endpoint to trigger it manual (#2622) --- supervisor/api/__init__.py | 1 + supervisor/api/resolution.py | 8 +++++++- supervisor/core.py | 1 - supervisor/resolution/module.py | 8 ++++++-- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/supervisor/api/__init__.py b/supervisor/api/__init__.py index b79934f63..a21c79be8 100644 --- a/supervisor/api/__init__.py +++ b/supervisor/api/__init__.py @@ -238,6 +238,7 @@ class RestAPI(CoreSysAttributes): "/resolution/issue/{issue}", api_resolution.dismiss_issue, ), + web.post("/resolution/healthcheck", api_resolution.healthcheck), ] ) diff --git a/supervisor/api/resolution.py b/supervisor/api/resolution.py index e46d46800..0d6cf2809 100644 --- a/supervisor/api/resolution.py +++ b/supervisor/api/resolution.py @@ -1,5 +1,6 @@ """Handle REST API for resoulution.""" -from typing import Any, Dict +import asyncio +from typing import Any, Awaitable, Dict from aiohttp import web import attr @@ -56,3 +57,8 @@ class APIResoulution(CoreSysAttributes): self.sys_resolution.dismiss_issue(issue) except ResolutionNotFound: raise APIError("The supplied UUID is not a valid issue") from None + + @api_process + def healthcheck(self, request: web.Request) -> Awaitable[None]: + """Run backend healthcheck.""" + return asyncio.shield(self.sys_resolution.healthcheck()) diff --git a/supervisor/core.py b/supervisor/core.py index acf3b7477..73842999c 100644 --- a/supervisor/core.py +++ b/supervisor/core.py @@ -244,7 +244,6 @@ class Core(CoreSysAttributes): self.sys_create_task(self.sys_host.reload()) self.sys_create_task(self.sys_updater.reload()) self.sys_create_task(self.sys_resolution.healthcheck()) - self.sys_create_task(self.sys_resolution.fixup.run_autofix()) self.state = CoreState.RUNNING self.sys_homeassistant.websocket.supervisor_update_event("supervisor", {}) diff --git a/supervisor/resolution/module.py b/supervisor/resolution/module.py index cb1f85874..e3fde375e 100644 --- a/supervisor/resolution/module.py +++ b/supervisor/resolution/module.py @@ -1,8 +1,9 @@ """Supervisor resolution center.""" -from datetime import time import logging from typing import List, Optional +from supervisor.const import CoreState + from ..coresys import CoreSys, CoreSysAttributes from ..exceptions import ResolutionError, ResolutionNotFound from .check import ResolutionCheck @@ -141,12 +142,15 @@ class ResolutionManager(CoreSysAttributes): # Schedule the healthcheck self.sys_scheduler.register_task(self.healthcheck, SCHEDULED_HEALTHCHECK) - self.sys_scheduler.register_task(self.fixup.run_autofix, time(hour=2)) async def healthcheck(self): """Scheduled task to check for known issues.""" await self.check.check_system() + # Run autofix if possible + if self.sys_core.state == CoreState.RUNNING: + await self.fixup.run_autofix() + # Create notification for any known issues await self.notify.issue_notifications()