runner

package
v0.22.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 28, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(ctx context.Context, state *State, cfg Config, sender Sender, logger *slog.Logger)

Run executes the periodic runner loop until ctx is canceled.

Types

type Config

type Config struct {
	LateAfter       time.Duration // Late window duration after check interval.
	CheckInterval   time.Duration // Polling interval for checks.
	AlertOnRecovery bool          // Whether to emit recovery alerts.
	AlertOnLate     bool          // Whether to emit late alerts.
}

Config controls the runner timing and alert behavior.

type HeartbeatType

type HeartbeatType int

HeartbeatType represents a heartbeat event.

const HeartbeatReceive HeartbeatType = iota // HeartbeatReceive represents a received heartbeat.

type Sender

type Sender interface {
	Late(now time.Time, since time.Duration, payload string)
	Missing(now time.Time, since time.Duration, payload string)
	Recovered(now time.Time, payload string)
	Transition(now time.Time, from Stage, to Stage, since time.Duration)
}

Sender delivers alerts for runner state transitions.

type Snapshot

type Snapshot struct {
	LastSeen    time.Time // Timestamp of last heartbeat.
	LastPayload string    // Body of last heartbeat payload.
	Stage       Stage     // Current stage.
}

Snapshot captures a consistent view of State.

type Stage

type Stage int

Stage represents the heartbeat state relative to thresholds.

const (
	// StageNever indicates the heartbeat is never seen.
	StageNever Stage = iota
	// StageOK indicates the heartbeat is within thresholds.
	StageOK
	// StageLate indicates the heartbeat is beyond the late threshold.
	StageLate
	// StageMissing indicates the heartbeat is beyond the missing threshold.
	StageMissing
)

func (Stage) String

func (s Stage) String() string

String returns the stage identifier.

type State

type State struct {
	// contains filtered or unexported fields
}

State stores the last seen heartbeat and alert metadata.

func NewState

func NewState() *State

NewState initializes a State in the OK stage.

func (*State) Mailbox

func (s *State) Mailbox() <-chan HeartbeatType

Mailbox returns the heartbeat event channel.

func (*State) MarkLate

func (s *State) MarkLate()

MarkLate sets the stage to late.

func (*State) MarkMissing

func (s *State) MarkMissing(now time.Time)

MarkMissing updates the state to missing and records the alert time.

func (*State) MarkOK

func (s *State) MarkOK()

MarkOK resets the stage to OK.

func (*State) Snapshot

func (s *State) Snapshot() Snapshot

Snapshot returns a copy of the current state.

func (*State) UpdateSeen

func (s *State) UpdateSeen(now time.Time, payload string) bool

UpdateSeen records a heartbeat payload and notifies the runner.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL