progress

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Broadcaster

type Broadcaster interface {
	UpdateProgress(queueID int, percentage int)
	UpdateProgressWithStage(queueID int, percentage int, stage string)
}

Broadcaster interface for updating progress

type OffsetTracker

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

OffsetTracker wraps a base tracker and adds an offset to progress updates. This is useful for cumulative progress tracking across multiple sequential operations where each operation reports progress from 0→N, but we want overall progress.

Example: Processing 3 files with 100, 50, 50 segments (200 total):

File 1: OffsetTracker{offset: 0, total: 200} → updates 0/200, 1/200, ..., 100/200
File 2: OffsetTracker{offset: 100, total: 200} → updates 100/200, 101/200, ..., 150/200
File 3: OffsetTracker{offset: 150, total: 200} → updates 150/200, 151/200, ..., 200/200

func NewOffsetTracker

func NewOffsetTracker(baseTracker *Tracker, offset, total int) *OffsetTracker

NewOffsetTracker creates a progress tracker that adds an offset to all updates. The offset represents work completed before this tracker's scope, and total represents the overall work across all operations.

func (*OffsetTracker) Update

func (ot *OffsetTracker) Update(current, total int)

Update reports progress by adding the offset to current before delegating to base tracker. This maintains cumulative progress across multiple sequential operations.

func (*OffsetTracker) UpdateAbsolute

func (ot *OffsetTracker) UpdateAbsolute(percentage int)

UpdateAbsolute delegates absolute percentage updates to the base tracker.

type ProgressBroadcaster

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

ProgressBroadcaster manages progress tracking for queue items

func NewProgressBroadcaster

func NewProgressBroadcaster() *ProgressBroadcaster

NewProgressBroadcaster creates a new progress broadcaster

func (*ProgressBroadcaster) BroadcastHealthChanged

func (pb *ProgressBroadcaster) BroadcastHealthChanged()

BroadcastHealthChanged sends a health-change notification to all SSE subscribers. Uses QueueID=0 and Status="health_changed" as a sentinel for health state changes.

func (*ProgressBroadcaster) BroadcastQueueChanged

func (pb *ProgressBroadcaster) BroadcastQueueChanged()

BroadcastQueueChanged sends a queue-change notification to all SSE subscribers. Uses QueueID=0 and Status="queue_changed" as a sentinel for non-progress queue events.

func (*ProgressBroadcaster) ClearProgress

func (pb *ProgressBroadcaster) ClearProgress(queueID int)

ClearProgress removes progress tracking for a completed or failed queue item

func (*ProgressBroadcaster) Close

func (pb *ProgressBroadcaster) Close() error

func (*ProgressBroadcaster) CreateTracker

func (pb *ProgressBroadcaster) CreateTracker(queueID, minPercent, maxPercent int) *Tracker

CreateTracker creates a progress tracker for a specific queue item with a percentage range

func (*ProgressBroadcaster) GetAllProgress

func (pb *ProgressBroadcaster) GetAllProgress() map[int]ProgressEntry

GetAllProgress returns a copy of all current progress states including stage labels. The returned map is used to build the initial SSE payload sent to new subscribers.

func (*ProgressBroadcaster) GetProgress

func (pb *ProgressBroadcaster) GetProgress(queueID int) (int, bool)

GetProgress returns the current progress percentage for a queue item.

func (*ProgressBroadcaster) HasSubscribers

func (pb *ProgressBroadcaster) HasSubscribers() bool

HasSubscribers reports whether at least one SSE client is connected.

func (*ProgressBroadcaster) NotifyComplete

func (pb *ProgressBroadcaster) NotifyComplete(queueID int, status string)

NotifyComplete broadcasts a terminal completion or failure event for a queue item and removes it from progress tracking. status should be "completed" or "failed".

func (*ProgressBroadcaster) Subscribe

func (pb *ProgressBroadcaster) Subscribe() (string, <-chan ProgressUpdate)

Subscribe creates a new SSE subscriber and returns a subscription ID and update channel

func (*ProgressBroadcaster) Unsubscribe

func (pb *ProgressBroadcaster) Unsubscribe(subID string)

Unsubscribe removes an SSE subscriber and closes its channel

func (*ProgressBroadcaster) UpdateProgress

func (pb *ProgressBroadcaster) UpdateProgress(queueID int, percentage int)

UpdateProgress updates the progress for a queue item (no stage label).

func (*ProgressBroadcaster) UpdateProgressWithStage

func (pb *ProgressBroadcaster) UpdateProgressWithStage(queueID int, percentage int, stage string)

UpdateProgressWithStage updates the progress for a queue item with an optional stage label.

type ProgressEntry

type ProgressEntry struct {
	Percentage int    `json:"percentage"`
	Stage      string `json:"stage,omitempty"`
}

ProgressEntry holds the current progress state for a single queue item. It is returned by GetAllProgress for the SSE initial payload.

type ProgressTracker

type ProgressTracker interface {
	Update(current, total int)
	UpdateAbsolute(percentage int)
}

ProgressTracker interface for types that can report progress

type ProgressUpdate

type ProgressUpdate struct {
	QueueID    int       `json:"queue_id"`
	Percentage int       `json:"percentage"`
	Stage      string    `json:"stage,omitempty"`  // e.g. "Parsing NZB", "Validating segments"
	Status     string    `json:"status,omitempty"` // "completed" or "failed" on terminal events
	Timestamp  time.Time `json:"timestamp"`
}

ProgressUpdate represents a progress update event

type Tracker

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

Tracker encapsulates progress updates for a specific queue item

func NewTracker

func NewTracker(broadcaster Broadcaster, queueID, minPercent, maxPercent int) *Tracker

NewTracker creates a progress tracker for a specific queue item with a percentage range

func (*Tracker) Update

func (pt *Tracker) Update(current, total int)

Update reports progress within the configured percentage range. Safe to call on a nil receiver (no-op).

func (*Tracker) UpdateAbsolute

func (pt *Tracker) UpdateAbsolute(percentage int)

UpdateAbsolute reports an absolute percentage value, bypassing the tracker's range. The stored stage label is still attached to the broadcast update.

func (*Tracker) WithStage

func (pt *Tracker) WithStage(stage string) *Tracker

WithStage sets a human-readable stage label that is attached to every progress update emitted by this tracker. Returns the same tracker for chaining.

Jump to

Keyboard shortcuts

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