Add unhealthy reasons to block message (#3948)

This commit is contained in:
Joakim Sørensen 2022-10-13 15:28:30 +02:00 committed by GitHub
parent 767c2bd91a
commit 9da4ea20a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 1 deletions

View File

@ -179,7 +179,7 @@ class Job(CoreSysAttributes):
if JobCondition.HEALTHY in used_conditions and not self.sys_core.healthy:
raise JobConditionException(
f"'{self._method.__qualname__}' blocked from execution, system is not healthy"
f"'{self._method.__qualname__}' blocked from execution, system is not healthy - {', '.join(self.sys_resolution.unhealthy)}"
)
if (

View File

@ -488,3 +488,27 @@ async def test_auto_update(coresys: CoreSys):
coresys.updater.auto_update = False
assert not await test.execute()
async def test_unhealthy(coresys: CoreSys, caplog: pytest.LogCaptureFixture):
"""Test the healthy decorator when unhealthy."""
class TestClass:
"""Test class."""
def __init__(self, coresys: CoreSys):
"""Initialize the test class."""
self.coresys = coresys
@Job(conditions=[JobCondition.HEALTHY])
async def execute(self) -> bool:
"""Execute the class method."""
return True
test = TestClass(coresys)
coresys.resolution.unhealthy = UnhealthyReason.SETUP
assert not await test.execute()
assert "blocked from execution, system is not healthy - setup" in caplog.text
coresys.jobs.ignore_conditions = [JobCondition.HEALTHY]
assert await test.execute()