activity

package
v0.1.147 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2026 License: GPL-2.0, GPL-3.0 Imports: 3 Imported by: 0

Documentation

Overview

Package activity provides concurrent-safe activity and alert tracking for the subflux UI status indicator.

Index

Constants

View Source
const DefaultPruneAge = 15 * time.Minute

DefaultPruneAge is the duration after which completed activities are pruned.

View Source
const TransientAlertTTL = 1 * time.Hour

TransientAlertTTL is the default TTL for transient alerts.

Variables

This section is empty.

Functions

This section is empty.

Types

type ActivitySource

type ActivitySource string //nolint:revive // stutters but renaming breaks callers

ActivitySource is a typed string for activity entry source values.

const (
	SourceScheduled ActivitySource = "scheduled"
	SourceManual    ActivitySource = "manual"
)

Activity source constants.

type Alert

type Alert struct {
	Time      time.Time     `json:"time"`
	Level     AlertLevel    `json:"level"` // "error", "warn", "info"
	Message   string        `json:"message"`
	Source    string        `json:"source"`
	Kind      AlertKind     `json:"kind"`
	TTL       time.Duration `json:"-"` // per-alert TTL override; 0 = use default
	ID        int           `json:"id"`
	Dismissed bool          `json:"dismissed"`
}

Alert represents an actionable error or informational message.

type AlertKind

type AlertKind string

AlertKind controls how an alert is displayed and dismissed.

const (
	// AlertPersistent requires manual dismissal by the user.
	AlertPersistent AlertKind = "persistent"
	// AlertTransient auto-expires after TransientAlertTTL.
	AlertTransient AlertKind = "transient"
)

type AlertLevel

type AlertLevel string

AlertLevel is a typed string for alert severity levels.

const (
	LevelError AlertLevel = "error"
	LevelWarn  AlertLevel = "warn"
	LevelInfo  AlertLevel = "info"
)

Alert level constants.

type AlertLog

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

AlertLog tracks actionable errors for the UI.

func NewAlertLog

func NewAlertLog(capacity int) *AlertLog

NewAlertLog creates an AlertLog with the given max capacity.

func (*AlertLog) AddAlert

func (al *AlertLog) AddAlert(source, message string, kind AlertKind, level AlertLevel, ttl time.Duration)

AddAlert appends an alert with the given level and optional TTL override.

func (*AlertLog) AlertsUnsafe

func (al *AlertLog) AlertsUnsafe() []Alert

AlertsUnsafe returns the internal alerts slice without copying. Caller must hold the lock.

func (*AlertLog) AppendAlert

func (al *AlertLog) AppendAlert(a Alert)

AppendAlert appends an alert directly (for test setup). Caller must hold the lock.

func (*AlertLog) Dismiss

func (al *AlertLog) Dismiss(id int) bool

Dismiss marks an alert as dismissed by ID.

func (*AlertLog) DismissBySource

func (al *AlertLog) DismissBySource(source string)

DismissBySource dismisses all undismissed persistent alerts from a source.

func (*AlertLog) Lock

func (al *AlertLog) Lock()

Lock acquires a write lock (for test manipulation).

func (*AlertLog) RLock

func (al *AlertLog) RLock()

RLock acquires a read lock (for test inspection).

func (*AlertLog) RUnlock

func (al *AlertLog) RUnlock()

RUnlock releases a read lock.

func (*AlertLog) Record

func (al *AlertLog) Record(source, message string)

Record adds a transient error alert.

func (*AlertLog) RecordInfo

func (al *AlertLog) RecordInfo(message string)

RecordInfo adds a short-lived informational alert for scan results.

func (*AlertLog) RecordPersistent

func (al *AlertLog) RecordPersistent(source, message string)

RecordPersistent adds a persistent error that requires manual dismissal.

func (*AlertLog) RecordWarn

func (al *AlertLog) RecordWarn(source, message string)

RecordWarn adds a transient warning alert.

func (*AlertLog) Unlock

func (al *AlertLog) Unlock()

Unlock releases a write lock.

func (*AlertLog) VisibleAlerts

func (al *AlertLog) VisibleAlerts() []Alert

VisibleAlerts returns a copy of non-dismissed, non-expired alerts.

type Entry

type Entry struct {
	StartedAt  time.Time      `json:"started_at"`
	EndedAt    *time.Time     `json:"ended_at,omitempty"`
	EndedAtVal time.Time      `json:"-"` // backing store for EndedAt to avoid heap alloc
	ID         string         `json:"id"`
	Action     string         `json:"action"`
	Detail     string         `json:"detail"`
	Source     ActivitySource `json:"source"` // "scheduled" or "manual"
	Done       bool           `json:"done"`
	Queued     bool           `json:"queued,omitempty"`
	Cancelled  bool           `json:"cancelled,omitempty"`
	Failed     bool           `json:"failed,omitempty"`
	Current    int            `json:"current,omitempty"`
	Total      int            `json:"total,omitempty"`
}

Entry represents an ongoing or recent action.

type Log

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

Log tracks recent actions for the UI status indicator.

func New

func New(maxItems int) *Log

New creates an ActivityLog with the given max capacity.

func (*Log) AppendEntry

func (a *Log) AppendEntry(e Entry)

AppendEntry appends an entry directly (for test setup). Caller must hold the lock.

func (*Log) Cancel

func (a *Log) Cancel(id string) bool

Cancel marks a queued activity as cancelled. Returns true if found and cancelled.

func (*Log) Dismiss

func (a *Log) Dismiss(id string)

Dismiss removes a completed activity by ID.

func (*Log) End

func (a *Log) End(id string)

End marks an activity as done.

func (*Log) Entries

func (a *Log) Entries() []Entry

Entries returns a snapshot of all entries (for serialization).

func (*Log) EntriesUnsafe

func (a *Log) EntriesUnsafe() []Entry

EntriesUnsafe returns the internal entries slice without copying. Caller must hold the lock.

func (*Log) Fail

func (a *Log) Fail(id string)

Fail marks an activity as done with failure.

func (*Log) IsCancelled

func (a *Log) IsCancelled(id string) bool

IsCancelled checks if an activity has been cancelled.

func (*Log) Lock

func (a *Log) Lock()

Lock acquires a write lock (for test manipulation).

func (*Log) Progress

func (a *Log) Progress(id string, current, total int, detail string)

Progress updates the current/total counters and detail for an activity.

func (*Log) PruneCompleted

func (a *Log) PruneCompleted(maxAge time.Duration)

PruneCompleted removes completed activities older than maxAge.

func (*Log) RLock

func (a *Log) RLock()

RLock acquires a read lock (for test inspection).

func (*Log) RUnlock

func (a *Log) RUnlock()

RUnlock releases a read lock.

func (*Log) SetQueued

func (a *Log) SetQueued(id string, queued bool)

SetQueued marks an activity as queued (waiting to run).

func (*Log) Start

func (a *Log) Start(action, detail string, source ActivitySource) string

Start records a new activity and returns its ID.

func (*Log) Unlock

func (a *Log) Unlock()

Unlock releases a write lock.

type WarnRecorder

type WarnRecorder interface {
	RecordWarn(source, msg string)
}

WarnRecorder is the narrow interface for recording warning alerts. Both manualops and polling consume this single-method contract. The concrete type AlertLog satisfies it via structural typing.

Jump to

Keyboard shortcuts

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