progress

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2025 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ReportProgress

func ReportProgress(ctx context.Context, percentage float64, message string) error

ReportProgress is a helper function to report progress from within handlers

func WithReporter

func WithReporter(ctx context.Context, reporter Reporter) context.Context

WithReporter adds a progress reporter to the context

Types

type BatchedReporter

type BatchedReporter struct {
	*Batcher
}

BatchedReporter wraps a Reporter with batching capabilities

func NewBatchedReporter

func NewBatchedReporter(requestID, connectionID string, connManager ConnectionManager, opts ...BatcherOption) *BatchedReporter

NewBatchedReporter creates a new batched reporter

type Batcher

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

Batcher batches progress updates to reduce WebSocket message volume

func NewBatcher

func NewBatcher(reporter Reporter, opts ...BatcherOption) *Batcher

NewBatcher creates a new progress update batcher

func (*Batcher) Complete

func (b *Batcher) Complete(result interface{}) error

Complete flushes any pending updates and marks as complete

func (*Batcher) Fail

func (b *Batcher) Fail(err error) error

Fail flushes any pending updates and marks as failed

func (*Batcher) Report

func (b *Batcher) Report(percentage float64, message string) error

Report adds an update to the batch

func (*Batcher) SetMetadata

func (b *Batcher) SetMetadata(key string, value interface{}) error

SetMetadata sets metadata for future updates

func (*Batcher) Shutdown

func (b *Batcher) Shutdown(ctx context.Context) error

Shutdown gracefully shuts down the batcher

type BatcherOption

type BatcherOption func(*Batcher)

BatcherOption configures the batcher

func WithFlushThreshold

func WithFlushThreshold(threshold float64) BatcherOption

WithFlushThreshold sets the percentage threshold for immediate flush

func WithInterval

func WithInterval(interval time.Duration) BatcherOption

WithInterval sets the batch interval

func WithMaxBatch

func WithMaxBatch(max int) BatcherOption

WithMaxBatch sets the maximum batch size

type ConnectionManager

type ConnectionManager interface {
	Send(ctx context.Context, connectionID string, message interface{}) error
	IsActive(ctx context.Context, connectionID string) bool
}

ConnectionManager interface for sending WebSocket messages

type DefaultReporter

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

DefaultReporter implements the Reporter interface

func NewReporter

func NewReporter(requestID, connectionID string, connManager ConnectionManager) *DefaultReporter

NewReporter creates a new progress reporter

func (*DefaultReporter) Complete

func (r *DefaultReporter) Complete(result interface{}) error

Complete sends a completion notification

func (*DefaultReporter) Fail

func (r *DefaultReporter) Fail(err error) error

Fail sends a failure notification

func (*DefaultReporter) Report

func (r *DefaultReporter) Report(percentage float64, message string) error

Report sends a progress update

func (*DefaultReporter) SetMetadata

func (r *DefaultReporter) SetMetadata(key string, value interface{}) error

SetMetadata adds metadata to future progress updates

type Reporter

type Reporter interface {
	// Report sends a progress update with percentage and message
	Report(percentage float64, message string) error

	// SetMetadata adds metadata to the progress update
	SetMetadata(key string, value interface{}) error

	// Complete marks the request as complete with the result
	Complete(result interface{}) error

	// Fail marks the request as failed with an error
	Fail(err error) error
}

Reporter provides progress reporting functionality for async requests

func FromContext

func FromContext(ctx context.Context) (Reporter, bool)

FromContext retrieves the progress reporter from context

type Update

type Update struct {
	RequestID  string
	Percentage float64
	Message    string
	Metadata   map[string]interface{}
	Error      error
	Timestamp  time.Time
}

Update represents a single progress update

Jump to

Keyboard shortcuts

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