fix(reporter): refresh last_heal_timestamp on every heal result
This commit is contained in:
1 parent
469a30df6a
commit
ecda631049
2 files changed
+25
-2
No files matched your search
+5
-2
@@ -137,8 +137,11 @@ class LocalStateReporter:
|
|||||||
)
|
)
|
||||||
if heal_result is not None:
|
if heal_result is not None:
|
||||||
effective_heal_result = heal_result
|
effective_heal_result = heal_result
|
||||||
if effective_last_heal_timestamp is None:
|
effective_last_heal_timestamp = (
|
||||||
effective_last_heal_timestamp = datetime.now().isoformat()
|
last_heal_timestamp
|
||||||
|
if last_heal_timestamp is not None
|
||||||
|
else datetime.now().isoformat()
|
||||||
|
)
|
||||||
|
|
||||||
now_epoch = time.time()
|
now_epoch = time.time()
|
||||||
checks_total = max(0, self._get_int(previous, "checks_total", 0))
|
checks_total = max(0, self._get_int(previous, "checks_total", 0))
|
||||||
|
|||||||
@@ -147,6 +147,26 @@ class ReporterStateTests(unittest.TestCase):
|
|||||||
|
|
||||||
self.assertEqual(first_ts, second_payload["last_heal_timestamp"])
|
self.assertEqual(first_ts, second_payload["last_heal_timestamp"])
|
||||||
|
|
||||||
|
@patch("reporter.datetime")
|
||||||
|
def test_update_status_refreshes_last_heal_timestamp_on_each_heal(self, datetime_mock):
|
||||||
|
with tempfile.TemporaryDirectory() as tmp_dir:
|
||||||
|
state_file = os.path.join(tmp_dir, "state.json")
|
||||||
|
reporter = LocalStateReporter(state_file=state_file, node_name="n1")
|
||||||
|
|
||||||
|
datetime_mock.now.side_effect = [
|
||||||
|
datetime.fromisoformat("2026-03-06T10:00:00"),
|
||||||
|
datetime.fromisoformat("2026-03-06T10:00:00"),
|
||||||
|
datetime.fromisoformat("2026-03-06T10:05:00"),
|
||||||
|
datetime.fromisoformat("2026-03-06T10:05:00"),
|
||||||
|
]
|
||||||
|
reporter.update_status(False, 1, heal_result="failed")
|
||||||
|
reporter.update_status(False, 1, heal_result="success")
|
||||||
|
|
||||||
|
with open(state_file, "r") as f:
|
||||||
|
payload = json.load(f)
|
||||||
|
|
||||||
|
self.assertEqual("2026-03-06T10:05:00", payload["last_heal_timestamp"])
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
Reference in new issue
Block a user