A heartbeat monitor has a secret ping URL instead of a target and regions. Jobs call it with GET, HEAD or POST after each run, or /fail with an optional message. When no ping arrives within the interval plus a grace period, a failure is recorded and evaluated like a checker result, so confirmations, maintenance and notifications apply. One API replica at a time checks deadlines. The URL is shown only to members who may edit the monitor, since it can report the job healthy. Closes #27 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
37 lines
934 B
Go
37 lines
934 B
Go
package check
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
)
|
|
|
|
// HeartbeatConfig configures a heartbeat monitor.
|
|
type HeartbeatConfig struct {
|
|
// GraceSeconds is how late a ping may be before the monitor counts as
|
|
// failed, to absorb jobs that run a little longer than usual.
|
|
GraceSeconds int `json:"grace_seconds"`
|
|
}
|
|
|
|
// DefaultHeartbeatGrace applies when no grace period is set.
|
|
const DefaultHeartbeatGrace = 60
|
|
|
|
type heartbeatCheck struct{}
|
|
|
|
func (heartbeatCheck) validate(_ string, config json.RawMessage) (json.RawMessage, error) {
|
|
c, err := decode[HeartbeatConfig](config)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if c.GraceSeconds == 0 {
|
|
c.GraceSeconds = DefaultHeartbeatGrace
|
|
}
|
|
if c.GraceSeconds < 0 || c.GraceSeconds > 86400 {
|
|
return nil, invalid("invalid_grace")
|
|
}
|
|
return encode(c), nil
|
|
}
|
|
|
|
func (heartbeatCheck) run(context.Context, Spec) Outcome {
|
|
return Outcome{Error: "heartbeat monitors are not run by checkers"}
|
|
}
|