watchdog

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package watchdog provides timeout enforcement for Smith worker processes.

The Watchdog monitors running workers and kills any that exceed the configured smith_timeout. It uses graceful shutdown (context cancellation) first, then forceful kill after a grace period.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type TrackedProcess

type TrackedProcess struct {
	// WorkerID is the worker's unique identifier.
	WorkerID string
	// BeadID is the bead being worked on.
	BeadID string
	// Anvil is the anvil name.
	Anvil string
	// StartedAt is when the process was started.
	StartedAt time.Time
	// Cancel cancels the process context (graceful shutdown).
	Cancel context.CancelFunc
	// Kill forcefully terminates the process.
	Kill func() error
	// Done returns a channel that closes when the process finishes.
	Done func() <-chan struct{}
}

TrackedProcess represents a running process being monitored.

type Watchdog

type Watchdog struct {
	// Timeout is the maximum duration a Smith process can run.
	Timeout time.Duration
	// GracePeriod is how long to wait after context cancellation before killing.
	GracePeriod time.Duration
	// contains filtered or unexported fields
}

Watchdog monitors running processes and enforces timeouts.

func New

func New(db *state.DB, timeout time.Duration) *Watchdog

New creates a new Watchdog with the given timeout.

func (*Watchdog) Run

func (w *Watchdog) Run(ctx context.Context)

Run starts the watchdog loop. It checks all tracked processes periodically and kills any that have exceeded the timeout. Blocks until ctx is cancelled.

func (*Watchdog) Track

func (w *Watchdog) Track(p *TrackedProcess)

Track adds a process to the watchdog's monitoring list.

func (*Watchdog) TrackedCount

func (w *Watchdog) TrackedCount() int

TrackedCount returns the number of currently tracked processes.

func (*Watchdog) Untrack

func (w *Watchdog) Untrack(workerID string)

Untrack removes a process from monitoring (e.g., completed normally).

Jump to

Keyboard shortcuts

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