Skip to content

Commit 3c80a4a

Browse files
committed
fix: re-alert only on the hour
1 parent 06f9fa2 commit 3c80a4a

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

pyth_observer/dispatch.py

Lines changed: 7 additions & 4 deletions
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)