Help us shape the future of Go! Take the 2026 Go Developer Survey

watchdog

package
v0.9.3 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type IdleStatus

type IdleStatus int
const (
	IdleStatusBornIdle IdleStatus = iota
	IdleStatusIdle
	IdleStatusNotIdle
)

type Watchdog

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

func NewWatchdog

func NewWatchdog(
	idleTimeout, bornIdleTimeout, offlineTimeout, consideredLostTimeout, tickerInterval time.Duration,
	updateWorker func(workerID int32, newStatus string) error,
	deleteWorker func(workerID int32) error,
	warmCheck func(workerID int32) (bool, time.Duration),
	reclaimWorkerTasks func(workerID int32) error,
	db *sql.DB,
) *Watchdog

func (*Watchdog) RebuildFromWorkers

func (w *Watchdog) RebuildFromWorkers(workers []WorkerInfo)

func (*Watchdog) ResyncActiveTasks added in v0.7.1

func (w *Watchdog) ResyncActiveTasks(ctx context.Context, db *sql.DB)

ResyncActiveTasks re-queries the DB for the current active task counts and fixes up any drift caused by TaskFinished calls that arrived between the initial FetchWorkersForWatchdog query and RebuildFromWorkers.

func (*Watchdog) Run

func (w *Watchdog) Run(stopChan <-chan struct{})

Main watchdog loop

func (*Watchdog) SetPermanent added in v0.7.4

func (w *Watchdog) SetPermanent(workerID int32, isPermanent bool)

SetPermanent updates the cached permanent flag for a worker.

func (*Watchdog) Snapshot added in v0.9.2

func (w *Watchdog) Snapshot() []WorkerSnapshot

Snapshot returns a point-in-time copy of the watchdog's per-worker state. Iteration is over the idleStatus map (every worker the watchdog is tracking, including permanent and offline ones — the metrics refresher can filter). Safe to call concurrently with checkIdle / TaskAccepted / TaskFinished (sync.Map handles the concurrency).

func (*Watchdog) TaskAccepted

func (w *Watchdog) TaskAccepted(workerID int32)

Called when a worker accepts a task (Assigned ➔ Accepted)

func (*Watchdog) TaskFinished

func (w *Watchdog) TaskFinished(workerID int32)

Called when a worker finishes a task (Success or Failure)

func (*Watchdog) WorkerDeleted

func (w *Watchdog) WorkerDeleted(workerID int32)

WorkerDeleted should be called when a worker is deleted from the database

func (*Watchdog) WorkerPinged

func (w *Watchdog) WorkerPinged(workerID int32)

Called when a worker sends a ping

func (*Watchdog) WorkerRegistered

func (w *Watchdog) WorkerRegistered(workerID int32, isPermanent bool)

Called when a worker is registered (comes online and is running)

func (*Watchdog) WorkerSpawned

func (w *Watchdog) WorkerSpawned(workerID int32, isPermanent bool)

Called right after we create the DB row + cloud deploy job, before the worker is ready

type WorkerInfo

type WorkerInfo struct {
	WorkerID    int32
	Status      string
	IsPermanent bool
	ActiveTasks int
	LastNotIdle *time.Time
}

type WorkerSnapshot added in v0.9.2

type WorkerSnapshot struct {
	WorkerID    int32
	IsPermanent bool
	// Seconds since lastNotIdle. -1 when the worker has never been
	// idle (still tracks a task) — the metrics side turns that into
	// NaN so the series is skipped by Prometheus queries.
	IdleSeconds float64
	// Watchdog's in-memory active-task count. Metrics computes drift
	// as (DB count) - (this value); steady-state should be 0 after
	// the 2026-09-10 retryTaskInternal + ResyncActiveTasks fixes.
	ActiveTasks int
}

WorkerSnapshot is a point-in-time read of everything the watchdog tracks per worker. Used by the metrics refresher (see server/metrics) so it can compute idle-seconds and active-task drift without holding a reference to the internal maps. Values are copies; safe to hand to any consumer.

Jump to

Keyboard shortcuts

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