runner

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package runner periodically executes a Probe and pushes the result into a State, invoking Reporters on transitions. Decouples probe execution from transport — transports read cached State instead of running checks per-request (matters for gRPC Watch, expensive checks, or bursty traffic).

Index

Constants

View Source
const (
	DefaultInterval = 5 * time.Second
	DefaultTimeout  = 2 * time.Second
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(*Runner)

Option configures a Runner.

func RunImmediately

func RunImmediately() Option

RunImmediately performs an initial check before the first tick. Default: false (state stays StatusUnknown until first tick).

func WithInterval

func WithInterval(d time.Duration) Option

func WithName

func WithName(n string) Option

func WithReporter

func WithReporter(rep reporter.Reporter) Option

func WithTimeout

func WithTimeout(d time.Duration) Option

type Runner

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

Runner polls a probe.Probe and updates a state.State.

Every evaluation — a scheduled tick or an explicit Check — runs under one mutex held across the probe call, the State update and the reporter call, so results land in State (and reach the reporter) strictly in evaluation order. A Runner must not be copied after first use.

func New

func New(p probe.Probe, s *state.State, opts ...Option) *Runner

New constructs a Runner. The provided state is updated on every tick.

func (*Runner) Check added in v1.1.0

func (r *Runner) Check(ctx context.Context) probe.Status

Check evaluates the probe right now, outside the tick schedule, and returns the resulting status. It behaves exactly like a tick: the probe is bounded by the configured timeout (StatusTimeout on expiry), the result is stored in State, and the reporter fires on a transition.

Check is safe to call before Run and concurrently with it; evaluations are serialized, so a Check waits for an in-flight tick (and vice versa) and the State always holds the result of the latest evaluation.

If ctx is canceled (before or during the evaluation), nothing is stored and no reporter fires — as with a tick on shutdown — and Check returns the current cached status: StatusUnknown if State has never been set.

func (*Runner) Run

func (r *Runner) Run(ctx context.Context)

Run blocks until ctx is canceled, periodically checking the probe.

func (*Runner) Start

func (r *Runner) Start(ctx context.Context)

Start launches Run in a goroutine and returns immediately.

Jump to

Keyboard shortcuts

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