Skip to content

Commit

Permalink
fix: treat temporary failures as activity
Browse files Browse the repository at this point in the history
When an activity check fails with a TemporaryCheckError, we now treat
that situation as activity to prevent unintentional shutdowns of the
system due to having a check configured wrongly or simply because of a
temporary name resolution error or alike.

Fixes: #589
  • Loading branch information
languitar committed Nov 19, 2024
1 parent ac39e1d commit 59e2d54
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/autosuspend/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def _safe_execute_activity(check: Activity, logger: logging.Logger) -> str | Non
return check.check()
except TemporaryCheckError:
logger.warning("Check %s failed. Ignoring...", check, exc_info=True)
return None
return f"Check {check.name} failed temporarily"


def execute_checks(
Expand Down
10 changes: 2 additions & 8 deletions tests/test_autosuspend.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,22 +294,16 @@ def test_all_called(self, mocker: MockerFixture) -> None:
matching_check.check.assert_called_once_with()
second_check.check.assert_called_once_with()

def test_ignore_temporary_errors(self, mocker: MockerFixture) -> None:
def test_treat_temporary_errors_as_activity(self, mocker: MockerFixture) -> None:
matching_check = mocker.MagicMock(spec=autosuspend.Activity)
matching_check.name = "foo"
matching_check.check.side_effect = autosuspend.TemporaryCheckError()
second_check = mocker.MagicMock()
second_check.name = "bar"
second_check.check.return_value = "matches"

assert (
autosuspend.execute_checks(
[matching_check, second_check], False, mocker.MagicMock()
)
autosuspend.execute_checks([matching_check], False, mocker.MagicMock())
is True
)
matching_check.check.assert_called_once_with()
second_check.check.assert_called_once_with()


class TestExecuteWakeups:
Expand Down

0 comments on commit 59e2d54

Please sign in to comment.