Optimize resolution checks / add endpoint to trigger it manual (#2622)

This commit is contained in:
Pascal Vizeli 2021-02-25 14:05:27 +01:00 committed by GitHub
parent ae3274e559
commit 115af4cadf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 4 deletions

View File

@ -238,6 +238,7 @@ class RestAPI(CoreSysAttributes):
"/resolution/issue/{issue}", "/resolution/issue/{issue}",
api_resolution.dismiss_issue, api_resolution.dismiss_issue,
), ),
web.post("/resolution/healthcheck", api_resolution.healthcheck),
] ]
) )

View File

@ -1,5 +1,6 @@
"""Handle REST API for resoulution.""" """Handle REST API for resoulution."""
from typing import Any, Dict import asyncio
from typing import Any, Awaitable, Dict
from aiohttp import web from aiohttp import web
import attr import attr
@ -56,3 +57,8 @@ class APIResoulution(CoreSysAttributes):
self.sys_resolution.dismiss_issue(issue) self.sys_resolution.dismiss_issue(issue)
except ResolutionNotFound: except ResolutionNotFound:
raise APIError("The supplied UUID is not a valid issue") from None 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())

View File

@ -244,7 +244,6 @@ class Core(CoreSysAttributes):
self.sys_create_task(self.sys_host.reload()) self.sys_create_task(self.sys_host.reload())
self.sys_create_task(self.sys_updater.reload()) self.sys_create_task(self.sys_updater.reload())
self.sys_create_task(self.sys_resolution.healthcheck()) self.sys_create_task(self.sys_resolution.healthcheck())
self.sys_create_task(self.sys_resolution.fixup.run_autofix())
self.state = CoreState.RUNNING self.state = CoreState.RUNNING
self.sys_homeassistant.websocket.supervisor_update_event("supervisor", {}) self.sys_homeassistant.websocket.supervisor_update_event("supervisor", {})

View File

@ -1,8 +1,9 @@
"""Supervisor resolution center.""" """Supervisor resolution center."""
from datetime import time
import logging import logging
from typing import List, Optional from typing import List, Optional
from supervisor.const import CoreState
from ..coresys import CoreSys, CoreSysAttributes from ..coresys import CoreSys, CoreSysAttributes
from ..exceptions import ResolutionError, ResolutionNotFound from ..exceptions import ResolutionError, ResolutionNotFound
from .check import ResolutionCheck from .check import ResolutionCheck
@ -141,12 +142,15 @@ class ResolutionManager(CoreSysAttributes):
# Schedule the healthcheck # Schedule the healthcheck
self.sys_scheduler.register_task(self.healthcheck, SCHEDULED_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): async def healthcheck(self):
"""Scheduled task to check for known issues.""" """Scheduled task to check for known issues."""
await self.check.check_system() 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 # Create notification for any known issues
await self.notify.issue_notifications() await self.notify.issue_notifications()