Documentation
¶
Index ¶
- type IdleStatus
- type Watchdog
- func (w *Watchdog) RebuildFromWorkers(workers []WorkerInfo)
- func (w *Watchdog) ResyncActiveTasks(ctx context.Context, db *sql.DB)
- func (w *Watchdog) Run(stopChan <-chan struct{})
- func (w *Watchdog) SetPermanent(workerID int32, isPermanent bool)
- func (w *Watchdog) Snapshot() []WorkerSnapshot
- func (w *Watchdog) TaskAccepted(workerID int32)
- func (w *Watchdog) TaskFinished(workerID int32)
- func (w *Watchdog) WorkerDeleted(workerID int32)
- func (w *Watchdog) WorkerPinged(workerID int32)
- func (w *Watchdog) WorkerRegistered(workerID int32, isPermanent bool)
- func (w *Watchdog) WorkerSpawned(workerID int32, isPermanent bool)
- type WorkerInfo
- type WorkerSnapshot
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
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) SetPermanent ¶ added in v0.7.4
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 ¶
Called when a worker accepts a task (Assigned ➔ Accepted)
func (*Watchdog) TaskFinished ¶
Called when a worker finishes a task (Success or Failure)
func (*Watchdog) WorkerDeleted ¶
WorkerDeleted should be called when a worker is deleted from the database
func (*Watchdog) WorkerPinged ¶
Called when a worker sends a ping
func (*Watchdog) WorkerRegistered ¶
Called when a worker is registered (comes online and is running)
func (*Watchdog) WorkerSpawned ¶
Called right after we create the DB row + cloud deploy job, before the worker is ready
type WorkerInfo ¶
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.