github.com/rotari-dev/rotari/internal/runwatch

Overview

package runwatch // import "github.com/rotari-dev/rotari/internal/runwatch"

Package runwatch finds runs that stopped without finishing, such as runs whose
coordinator was killed, and records them for the Web inbox. A run's own process
cannot report that it was killed; rotari web looks for such runs instead.
A run whose coordinator is on another host is judged by its heartbeat, which
only suggests that it stopped.

Constants

const Interval = 30 * time.Second
    Interval is how often rotari web looks for interrupted runs.

const UnresponsiveAfter = state.HeartbeatStaleAfter
    UnresponsiveAfter is how long a remote run's heartbeat must stay unchanged,
    by the watcher's own clock, before the run is reported unresponsive.

Types

type Watcher struct {
	// Has unexported fields.
}
    Watcher finds runs that stopped without finishing and records them for the
    Web inbox. A local run whose coordinator is dead is interrupted. An active
    run whose coordinator is on another host or in another PID namespace, which
    this host cannot check, is unresponsive once its heartbeat has not changed
    for UnresponsiveAfter. A Watcher remembers the heartbeats it saw between
    calls of Report, so one watcher must be kept for the life of the process;
    it is not safe for concurrent use.

func NewWatcher() *Watcher
    NewWatcher returns a Watcher that has seen no heartbeat yet, so it calls no
    run unresponsive before UnresponsiveAfter has passed.

func (watcher *Watcher) Report(log notificationlog.Log, baseDirs []string, now time.Time) (int, error)
    Report records a run.interrupted notification for each run in baseDirs
    that project.Inspect finds interrupted, and a run.unresponsive one for each
    remote run whose heartbeat has stopped, unless the run already has one.
    A project whose state lock is held is looked at again on the next call.
    It returns how many notifications it recorded; a project it cannot inspect
    or record is an error that does not stop the others.