mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-07-16 05:36:29 +00:00
Improve message handling of job condition (#2791)
This commit is contained in:
parent
fd98d38125
commit
d3e4bb7219
@ -34,6 +34,10 @@ class JobException(HassioError):
|
|||||||
"""Base job exception."""
|
"""Base job exception."""
|
||||||
|
|
||||||
|
|
||||||
|
class JobConditionException(JobException):
|
||||||
|
"""Exception happening for job conditions."""
|
||||||
|
|
||||||
|
|
||||||
# HomeAssistant
|
# HomeAssistant
|
||||||
|
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ import sentry_sdk
|
|||||||
|
|
||||||
from ..const import CoreState
|
from ..const import CoreState
|
||||||
from ..coresys import CoreSysAttributes
|
from ..coresys import CoreSysAttributes
|
||||||
from ..exceptions import HassioError, JobException
|
from ..exceptions import HassioError, JobConditionException, JobException
|
||||||
from ..resolution.const import MINIMUM_FREE_SPACE_THRESHOLD, ContextType, IssueType
|
from ..resolution.const import MINIMUM_FREE_SPACE_THRESHOLD, ContextType, IssueType
|
||||||
from .const import JobCondition, JobExecutionLimit
|
from .const import JobCondition, JobExecutionLimit
|
||||||
|
|
||||||
@ -75,10 +75,16 @@ class Job(CoreSysAttributes):
|
|||||||
job = self.sys_jobs.get_job(self.name)
|
job = self.sys_jobs.get_job(self.name)
|
||||||
|
|
||||||
# Handle condition
|
# Handle condition
|
||||||
if self.conditions and not self._check_conditions():
|
if self.conditions:
|
||||||
if self.on_condition is None:
|
try:
|
||||||
return
|
self._check_conditions()
|
||||||
raise self.on_condition()
|
except JobConditionException as err:
|
||||||
|
error_msg = str(err)
|
||||||
|
if self.on_condition is None:
|
||||||
|
_LOGGER.info(error_msg)
|
||||||
|
return
|
||||||
|
_LOGGER.warning(error_msg)
|
||||||
|
raise self.on_condition(error_msg) from None
|
||||||
|
|
||||||
# Handle exection limits
|
# Handle exection limits
|
||||||
if self.limit in (JobExecutionLimit.SINGLE_WAIT, JobExecutionLimit.ONCE):
|
if self.limit in (JobExecutionLimit.SINGLE_WAIT, JobExecutionLimit.ONCE):
|
||||||
@ -124,45 +130,35 @@ class Job(CoreSysAttributes):
|
|||||||
)
|
)
|
||||||
|
|
||||||
if JobCondition.HEALTHY in used_conditions and not self.sys_core.healthy:
|
if JobCondition.HEALTHY in used_conditions and not self.sys_core.healthy:
|
||||||
_LOGGER.warning(
|
raise JobConditionException(
|
||||||
"'%s' blocked from execution, system is not healthy",
|
f"'{self._method.__qualname__}' blocked from execution, system is not healthy"
|
||||||
self._method.__qualname__,
|
|
||||||
)
|
)
|
||||||
return False
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
JobCondition.RUNNING in used_conditions
|
JobCondition.RUNNING in used_conditions
|
||||||
and self.sys_core.state != CoreState.RUNNING
|
and self.sys_core.state != CoreState.RUNNING
|
||||||
):
|
):
|
||||||
_LOGGER.warning(
|
raise JobConditionException(
|
||||||
"'%s' blocked from execution, system is not running - %s",
|
f"'{self._method.__qualname__}' blocked from execution, system is not running - {self.sys_core.state!s}"
|
||||||
self._method.__qualname__,
|
|
||||||
self.sys_core.state,
|
|
||||||
)
|
)
|
||||||
return False
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
JobCondition.FREE_SPACE in used_conditions
|
JobCondition.FREE_SPACE in used_conditions
|
||||||
and self.sys_host.info.free_space < MINIMUM_FREE_SPACE_THRESHOLD
|
and self.sys_host.info.free_space < MINIMUM_FREE_SPACE_THRESHOLD
|
||||||
):
|
):
|
||||||
_LOGGER.warning(
|
|
||||||
"'%s' blocked from execution, not enough free space (%sGB) left on the device",
|
|
||||||
self._method.__qualname__,
|
|
||||||
self.sys_host.info.free_space,
|
|
||||||
)
|
|
||||||
self.sys_resolution.create_issue(IssueType.FREE_SPACE, ContextType.SYSTEM)
|
self.sys_resolution.create_issue(IssueType.FREE_SPACE, ContextType.SYSTEM)
|
||||||
return False
|
raise JobConditionException(
|
||||||
|
f"'{self._method.__qualname__}' blocked from execution, not enough free space ({self.sys_host.info.free_space}GB) left on the device"
|
||||||
|
)
|
||||||
|
|
||||||
if (
|
if (
|
||||||
JobCondition.INTERNET_SYSTEM in self.conditions
|
JobCondition.INTERNET_SYSTEM in self.conditions
|
||||||
and not self.sys_supervisor.connectivity
|
and not self.sys_supervisor.connectivity
|
||||||
and self.sys_core.state in (CoreState.SETUP, CoreState.RUNNING)
|
and self.sys_core.state in (CoreState.SETUP, CoreState.RUNNING)
|
||||||
):
|
):
|
||||||
_LOGGER.warning(
|
raise JobConditionException(
|
||||||
"'%s' blocked from execution, no supervisor internet connection",
|
f"'{self._method.__qualname__}' blocked from execution, no supervisor internet connection"
|
||||||
self._method.__qualname__,
|
|
||||||
)
|
)
|
||||||
return False
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
JobCondition.INTERNET_HOST in self.conditions
|
JobCondition.INTERNET_HOST in self.conditions
|
||||||
@ -170,20 +166,14 @@ class Job(CoreSysAttributes):
|
|||||||
and not self.sys_host.network.connectivity
|
and not self.sys_host.network.connectivity
|
||||||
and self.sys_core.state in (CoreState.SETUP, CoreState.RUNNING)
|
and self.sys_core.state in (CoreState.SETUP, CoreState.RUNNING)
|
||||||
):
|
):
|
||||||
_LOGGER.warning(
|
raise JobConditionException(
|
||||||
"'%s' blocked from execution, no host internet connection",
|
f"'{self._method.__qualname__}' blocked from execution, no host internet connection"
|
||||||
self._method.__qualname__,
|
|
||||||
)
|
)
|
||||||
return False
|
|
||||||
|
|
||||||
if JobCondition.HAOS in self.conditions and not self.sys_hassos.available:
|
if JobCondition.HAOS in self.conditions and not self.sys_hassos.available:
|
||||||
_LOGGER.warning(
|
raise JobConditionException(
|
||||||
"'%s' blocked from execution, no Home Assistant OS available",
|
f"'{self._method.__qualname__}' blocked from execution, no Home Assistant OS available"
|
||||||
self._method.__qualname__,
|
|
||||||
)
|
)
|
||||||
return False
|
|
||||||
|
|
||||||
return True
|
|
||||||
|
|
||||||
async def _acquire_exection_limit(self) -> None:
|
async def _acquire_exection_limit(self) -> None:
|
||||||
"""Process exection limits."""
|
"""Process exection limits."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user