tracking

package
v1.3.9 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2026 License: Apache-2.0 Imports: 6 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cooldown

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

Cooldown wraps a Reporter and limits how frequently updates are delivered for each status ID. Terminal states (completed, failed, skipped) are always delivered immediately. Non-terminal updates are delivered at most once per the configured interval; the latest pending status is flushed when the interval elapses or when a terminal state arrives.

func NewCooldown

func NewCooldown(inner Reporter, interval time.Duration) *Cooldown

NewCooldown creates a Cooldown wrapping the given reporter with the specified minimum interval between deliveries per status ID.

func (*Cooldown) Close

func (c *Cooldown) Close() error

Close flushes all pending statuses and stops all timers.

func (*Cooldown) OnChange

func (c *Cooldown) OnChange(ctx context.Context, status task.Status) error

OnChange receives a status update. Terminal states flush immediately. Non-terminal states are throttled to at most one delivery per interval.

type DBReporter

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

DBReporter implements Reporter by persisting status changes to the database.

func NewDBReporter

func NewDBReporter(repo task.StatusStore, logger zerolog.Logger) *DBReporter

NewDBReporter creates a new DBReporter.

func (*DBReporter) OnChange

func (r *DBReporter) OnChange(ctx context.Context, status task.Status) error

OnChange persists the task status to the database.

type LoggingReporter

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

LoggingReporter implements Reporter by logging status changes.

func NewLoggingReporter

func NewLoggingReporter(logger zerolog.Logger) *LoggingReporter

NewLoggingReporter creates a new LoggingReporter.

func (*LoggingReporter) OnChange

func (r *LoggingReporter) OnChange(_ context.Context, status task.Status) error

OnChange logs the task status change.

type Reporter

type Reporter interface {
	// OnChange is called when a task status changes.
	OnChange(ctx context.Context, status task.Status) error
}

Reporter defines the interface for progress reporting modules. Implementations receive notifications when task status changes.

type Tracker

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

Tracker provides progress tracking with automatic notification to subscribers. It wraps Status and propagates state changes to registered reporters.

func NewTracker

func NewTracker(status task.Status, logger zerolog.Logger) *Tracker

NewTracker creates a new progress tracker wrapping the given Status.

func TrackerForOperation

func TrackerForOperation(
	operation task.Operation,
	logger zerolog.Logger,
	trackableType task.TrackableType,
	trackableID int64,
) *Tracker

TrackerForOperation creates a new Tracker for the given operation.

func (*Tracker) Child

func (t *Tracker) Child(operation task.Operation) *Tracker

Child creates a child tracker for a sub-operation. The child inherits the parent's subscribers, trackable info, and labels.

func (*Tracker) Complete

func (t *Tracker) Complete(ctx context.Context)

Complete marks the task as completed.

func (*Tracker) Fail

func (t *Tracker) Fail(ctx context.Context, errMsg string)

Fail marks the task as failed with an error message.

func (*Tracker) Notify

func (t *Tracker) Notify(ctx context.Context)

Notify explicitly notifies all subscribers of the current status. Use this after initial setup to announce the tracker's existence.

func (*Tracker) SetCurrent

func (t *Tracker) SetCurrent(ctx context.Context, current int, message string)

SetCurrent updates the current progress count and optionally a message.

func (*Tracker) SetTotal

func (t *Tracker) SetTotal(ctx context.Context, total int)

SetTotal sets the total count for progress tracking.

func (*Tracker) Skip

func (t *Tracker) Skip(ctx context.Context, reason string)

Skip marks the task as skipped with a reason.

func (*Tracker) Status

func (t *Tracker) Status() task.Status

Status returns a copy of the current Status.

func (*Tracker) Subscribe

func (t *Tracker) Subscribe(reporter Reporter)

Subscribe adds a reporter to receive status change notifications.

func (*Tracker) WithLabel added in v1.1.2

func (t *Tracker) WithLabel(key, value string)

WithLabel sets a label on the tracker's status for log context.

Jump to

Keyboard shortcuts

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