taskmonitor

package
v0.0.18 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package taskmonitor is the M4 of ADR-0038 — a reusable widget that observes task.> over the bus and renders an in-flight list (with progress bar + per-row cancel button) and a rolling history of finished tasks. Failures expand into an errorview chain renderer directly, so an eh.MarshalError-shaped TaskError payload reads back with the same look as anywhere else in the runtime.

Construction follows the producer-handle pattern: callers pass a task.TaskApiI (typically from task.ForApp(MountCtx)), an IdStack-scoped idPrefix, and an Opts struct. Start subscribes the widget to task.> and (optionally) seeds the in-flight map from the supervisor's task.list.inflight snapshot. Stop tears down cleanly. Render is a single call inside a panel / scroll area.

The widget is intentionally stateless about identity — it does not know its consumer's AppId or RunId. Audit + identity propagation happen at the producer side via task.ForApp; the monitor's job is purely presentation.

Index

Constants

View Source
const DefaultMaxHistory = 20

DefaultMaxHistory caps the rolling history pane. Older terminal rows fall off the front; reads beyond this require the supervisor's audit trail.

Variables

View Source
var PackageProps = packageprops.Props{
	WASMWASI:         packageprops.WASMBlocked,
	WASMJS:           packageprops.WASMBlocked,
	WASMFreestanding: packageprops.WASMBlocked,
}

PackageProps records this package's curated properties (ADR-0080). Seeded by `wasmsurvey props generate`; curate by hand, then `wasmsurvey props verify`.

Functions

This section is empty.

Types

type Inst

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

Inst is the widget instance. Construct via New, then drive Start / Render / Stop from the host's frame loop.

Goroutine safety: ObserverI callbacks land on the bus dispatch goroutine (synchronous for in-proc, separate goroutine for NATS in M4); Render runs on the host's frame goroutine. The mutex guards the in-memory state shared between the two; Render snapshots under the lock and renders outside it.

func New

func New(api task.TaskApiI, ids *c.WidgetIdStack, idPrefix string, opts Opts) (inst *Inst)

New constructs a monitor bound to api. idPrefix scopes every widget id under the caller's ids stack — pass a stable short string so two monitors in the same panel don't collide.

func (*Inst) HistoryCount

func (inst *Inst) HistoryCount() (n int)

func (*Inst) InflightCount

func (inst *Inst) InflightCount() (n int)

InflightCount + HistoryCount expose row counts for callers that want to render a header summary or status line outside the widget body.

func (*Inst) OnCancel

func (inst *Inst) OnCancel(cn taskcancel.TaskCancel)

func (*Inst) OnCreated

func (inst *Inst) OnCreated(cr taskcreated.TaskCreated)

func (*Inst) OnDone

func (inst *Inst) OnDone(d taskdone.TaskDone)

func (*Inst) OnError

func (inst *Inst) OnError(e taskerror.TaskError)

func (*Inst) OnProgress

func (inst *Inst) OnProgress(p taskprogress.TaskProgress)

func (*Inst) Render

func (inst *Inst) Render()

Render draws the widget body. Single-threaded — the host's frame goroutine. Snapshots state under the lock then renders without it so ObserverI callbacks aren't blocked behind the egui scope.

func (*Inst) Start

func (inst *Inst) Start() (err error)

Start attaches the observer to the bus. Idempotent: a second call returns an error without altering state. Seeds from supervisor when Opts.SeedFromSupervisor is set; a failed seed is logged-by-caller (the returned err is best-effort) but does not block subscribing.

func (*Inst) Stop

func (inst *Inst) Stop() (err error)

Stop unsubscribes. Safe to call on a non-started monitor (no-op).

type Opts

type Opts struct {
	// MaxHistory is the rolling-window size for the history pane.
	// Zero ⇒ DefaultMaxHistory.
	MaxHistory int

	// DefaultOpen sets the initial collapsed/expanded state of both
	// the In-flight and History collapsing headers. Default true so
	// consumers see content immediately.
	DefaultOpen bool

	// SeedFromSupervisor causes Start to issue a single
	// task.list.inflight Request through the api to populate the
	// in-flight map before subscribing. When false (default), the
	// widget starts empty and fills as new task.created events
	// arrive. Set true when attaching to a long-running runtime so
	// already-running tasks become visible immediately.
	SeedFromSupervisor bool
}

Opts configures the widget at construction. Zero value is valid (DefaultOpen on, MaxHistory = DefaultMaxHistory).

Jump to

Keyboard shortcuts

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