Skip to content

Commit 0551946

Browse files
authored
fix: re-alert only on the hour (#84)
* fix: re-alert only on the hour * bump
1 parent 06f9fa2 commit 0551946

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ ignore_missing_imports = true
44

55
[tool.poetry]
66
name = "pyth-observer"
7-
version = "0.3.2"
7+
version = "0.3.3"
88
description = "Alerts and stuff"
99
authors = []
1010
readme = "README.md"

pyth_observer/dispatch.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -197,13 +197,16 @@ async def process_zenduty_events(self, current_time):
197197
to_remove.append(identifier)
198198
# Raise alert if failed > $threshold times within the last 5m window
199199
# or if already alerted and not yet resolved.
200-
# Re-alert every 5 minutes but not more often.
200+
# Re-alert at the start of each hour but not more often.
201201
elif (
202202
info["failures"] >= alert_threshold or (info["sent"] and not resolved)
203203
) and (
204-
not info.get("last_alert")
205-
or current_time - datetime.fromisoformat(info["last_alert"])
206-
> timedelta(minutes=5)
204+
not info.get("last_alert") # First alert - send immediately
205+
or ( # Subsequent alerts - send at the start of each hour
206+
current_time - datetime.fromisoformat(info["last_alert"])
207+
> timedelta(minutes=5)
208+
and current_time.minute == 0 # Only alert at the start of each hour
209+
)
207210
):
208211
logger.debug(f"Raising Zenduty alert {identifier}")
209212
self.open_alerts[identifier]["sent"] = True

0 commit comments

Comments
 (0)