progress

package
v0.0.1-alpha6 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2026 License: MIT Imports: 6 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)
}

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) 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]int

GetAllProgress returns a copy of all current progress states

func (*ProgressBroadcaster) GetProgress

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

GetProgress returns the current progress for a queue item

func (*ProgressBroadcaster) HasSubscribers

func (pb *ProgressBroadcaster) HasSubscribers() bool

HasSubscribers reports whether at least one SSE client is connected.

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

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"`
	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 This is useful for final progress updates (e.g., 100%) when the tracker's range doesn't cover the full 0-100% spectrum

Jump to

Keyboard shortcuts

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