feat(store): allow heartbeat monitors and find overdue ones
Refs #27 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
This commit is contained in:
1 parent
4635defef3
commit
04eff67e56
4 files changed
+125
No files matched your search
@@ -0,0 +1,16 @@
|
||||
-- name: HeartbeatMonitor :one
|
||||
-- System scope: the monitor a ping token belongs to.
|
||||
SELECT id, org_id, interval_seconds, confirmations, enabled
|
||||
FROM monitors WHERE type = 'heartbeat' AND target = $1;
|
||||
|
||||
-- name: HeartbeatsDue :many
|
||||
-- System scope: enabled heartbeat monitors with their grace period and
|
||||
-- since when they are being waited for: the latest result, or the last
|
||||
-- change of the monitor, which covers new and re-enabled ones. The result
|
||||
-- lookup is bounded because the longest interval plus grace is two days.
|
||||
SELECT m.id, m.org_id, m.interval_seconds, m.confirmations,
|
||||
coalesce((m.config->>'grace_seconds')::integer, 0)::integer AS grace_seconds,
|
||||
greatest(m.updated_at, coalesce((SELECT max(r.time) FROM check_results r
|
||||
WHERE r.org_id = m.org_id AND r.monitor_id = m.id AND r.time > now() - interval '3 days'), m.updated_at))::timestamptz AS waiting_since
|
||||
FROM monitors m
|
||||
WHERE m.type = 'heartbeat' AND m.enabled;
|
||||
Reference in new issue
Block a user