Documentation
¶
Overview ¶
Package activity provides concurrent-safe activity and alert tracking for the subflux UI status indicator.
Index ¶
- Constants
- type ActivitySource
- type Alert
- type AlertKind
- type AlertLevel
- type AlertLog
- func (al *AlertLog) AddAlert(source, message string, kind AlertKind, level AlertLevel, ttl time.Duration)
- func (al *AlertLog) AlertsUnsafe() []Alert
- func (al *AlertLog) AppendAlert(a Alert)
- func (al *AlertLog) Dismiss(id int) bool
- func (al *AlertLog) DismissBySource(source string)
- func (al *AlertLog) Lock()
- func (al *AlertLog) RLock()
- func (al *AlertLog) RUnlock()
- func (al *AlertLog) Record(source, message string)
- func (al *AlertLog) RecordInfo(message string)
- func (al *AlertLog) RecordPersistent(source, message string)
- func (al *AlertLog) RecordWarn(source, message string)
- func (al *AlertLog) Unlock()
- func (al *AlertLog) VisibleAlerts() []Alert
- type Entry
- type Log
- func (a *Log) AppendEntry(e Entry)
- func (a *Log) Cancel(id string) bool
- func (a *Log) Dismiss(id string)
- func (a *Log) End(id string)
- func (a *Log) Entries() []Entry
- func (a *Log) EntriesUnsafe() []Entry
- func (a *Log) Fail(id string)
- func (a *Log) IsCancelled(id string) bool
- func (a *Log) Lock()
- func (a *Log) Progress(id string, current, total int, detail string)
- func (a *Log) PruneCompleted(maxAge time.Duration)
- func (a *Log) RLock()
- func (a *Log) RUnlock()
- func (a *Log) SetQueued(id string, queued bool)
- func (a *Log) Start(action, detail string, source ActivitySource) string
- func (a *Log) Unlock()
- type WarnRecorder
Constants ¶
const DefaultPruneAge = 15 * time.Minute
DefaultPruneAge is the duration after which completed activities are pruned.
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 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 ¶
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 ¶
AlertsUnsafe returns the internal alerts slice without copying. Caller must hold the lock.
func (*AlertLog) AppendAlert ¶
AppendAlert appends an alert directly (for test setup). Caller must hold the lock.
func (*AlertLog) DismissBySource ¶
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) RecordInfo ¶
RecordInfo adds a short-lived informational alert for scan results.
func (*AlertLog) RecordPersistent ¶
RecordPersistent adds a persistent error that requires manual dismissal.
func (*AlertLog) RecordWarn ¶
RecordWarn adds a transient warning alert.
func (*AlertLog) VisibleAlerts ¶
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 (*Log) AppendEntry ¶
AppendEntry appends an entry directly (for test setup). Caller must hold the lock.
func (*Log) Cancel ¶
Cancel marks a queued activity as cancelled. Returns true if found and cancelled.
func (*Log) EntriesUnsafe ¶
EntriesUnsafe returns the internal entries slice without copying. Caller must hold the lock.
func (*Log) IsCancelled ¶
IsCancelled checks if an activity has been cancelled.
func (*Log) PruneCompleted ¶
PruneCompleted removes completed activities older than maxAge.
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.