Skip to content

Commit

Permalink
fix: re-alert only on the hour (#84)
Browse files Browse the repository at this point in the history
* fix: re-alert only on the hour

* bump
  • Loading branch information
cctdaniel authored Jan 9, 2025
1 parent 06f9fa2 commit 0551946
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ignore_missing_imports = true

[tool.poetry]
name = "pyth-observer"
version = "0.3.2"
version = "0.3.3"
description = "Alerts and stuff"
authors = []
readme = "README.md"
Expand Down
11 changes: 7 additions & 4 deletions pyth_observer/dispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,13 +197,16 @@ async def process_zenduty_events(self, current_time):
to_remove.append(identifier)
# Raise alert if failed > $threshold times within the last 5m window
# or if already alerted and not yet resolved.
# Re-alert every 5 minutes but not more often.
# Re-alert at the start of each hour but not more often.
elif (
info["failures"] >= alert_threshold or (info["sent"] and not resolved)
) and (
not info.get("last_alert")
or current_time - datetime.fromisoformat(info["last_alert"])
> timedelta(minutes=5)
not info.get("last_alert") # First alert - send immediately
or ( # Subsequent alerts - send at the start of each hour
current_time - datetime.fromisoformat(info["last_alert"])
> timedelta(minutes=5)
and current_time.minute == 0 # Only alert at the start of each hour
)
):
logger.debug(f"Raising Zenduty alert {identifier}")
self.open_alerts[identifier]["sent"] = True
Expand Down

0 comments on commit 0551946

Please sign in to comment.