progress

package
v0.59.0 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var LabelKeyTitle = typedmap.NewTypedKey[string]("khi.google.com/inspection/progress-title")

LabelKeyTitle is the task label key used to store a human-readable title for progress display.

Functions

func ForEach

func ForEach[T any](ctx context.Context, items []T, fn func(index int, item T) error, opts ...TrackerOption) error

ForEach iterates over a slice synchronously while automatically tracking progress, speed, and ETA.

func FromContext

FromContext retrieves the TaskProgressMetadata bound to the context, returning a no-op instance if absent.

func Report

func Report(ctx context.Context, ratio float32, message string)

Report updates the task progress completion ratio (0.0 to 1.0) and message directly from context.

func ReportIndeterminate

func ReportIndeterminate(ctx context.Context, message string)

ReportIndeterminate marks the current task progress as indeterminate with the given status message.

func ResolveTitle

func ResolveTitle(task coretask.UntypedTask) string

ResolveTitle determines the display title for a task using its explicit progress title label or its shortened task ID.

func TaskInterceptor

func TaskInterceptor(ctx context.Context, task coretask.UntypedTask, next func(context.Context) (any, error)) (any, error)

TaskInterceptor attaches a TaskProgressMetadata to the task execution context and resolves it when the task completes. It also wraps task execution in a task-scoped cancelable context so any background progress trackers are cleanly stopped upon task exit.

func WithContext

WithContext embeds a TaskProgressMetadata instance into the provided context.

func WithTitle

func WithTitle(title string) coretask.LabelOpt

WithTitle returns a task label option that specifies a human-readable title for progress display.

Types

type RatioTracker

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

RatioTracker tracks continuous ratio progress combined with cumulative item counts, used for streaming log queries.

func NewRatioTracker

func NewRatioTracker(ctx context.Context, opts ...TrackerOption) *RatioTracker

NewRatioTracker creates a tracker tailored for streaming operations where completion ratio and item counts arrive asynchronously.

func (*RatioTracker) Done

func (r *RatioTracker) Done()

Done marks the tracker complete if no streaming updates were reported.

func (*RatioTracker) Update

func (r *RatioTracker) Update(ratio float32, count int, opts ...RatioUpdateOption)

Update records the latest completion ratio (0.0 to 1.0) and cumulative item count, computing speed and ETA.

type RatioUpdateOption

type RatioUpdateOption func(*ratioUpdateState)

RatioUpdateOption provides additional context when updating a RatioTracker.

func WithStep

func WithStep(currentStep, totalSteps int) RatioUpdateOption

WithStep annotates the progress message with multi-step call indices, such as "2/5".

type Tracker

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

Tracker manages thread-safe progress counting, throughput calculation, and ETA estimation for discrete items.

func NewTracker

func NewTracker(ctx context.Context, total int, opts ...TrackerOption) *Tracker

NewTracker creates and starts a background progress tracker for a known total number of discrete items. If total <= 0, the tracker automatically reports indeterminate progress until Done is called.

func (*Tracker) Add

func (t *Tracker) Add(delta int)

Add adds delta to the completed item count in a thread-safe manner.

func (*Tracker) Done

func (t *Tracker) Done()

Done stops the background reporting ticker and flushes the latest progress state.

func (*Tracker) Inc

func (t *Tracker) Inc()

Inc increments the completed item count by 1 in a thread-safe manner.

type TrackerOption

type TrackerOption func(*trackerConfig)

TrackerOption configures a Tracker or RatioTracker.

func WithUnit

func WithUnit(unit string) TrackerOption

WithUnit specifies the unit name for processed items, such as "logs", "chunks", or "manifests".

Jump to

Keyboard shortcuts

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