Documentation
¶
Index ¶
- Variables
- func ForEach[T any](ctx context.Context, items []T, fn func(index int, item T) error, ...) error
- func FromContext(ctx context.Context) *inspectionmetadata.TaskProgressMetadata
- func Report(ctx context.Context, ratio float32, message string)
- func ReportIndeterminate(ctx context.Context, message string)
- func ResolveTitle(task coretask.UntypedTask) string
- func TaskInterceptor(ctx context.Context, task coretask.UntypedTask, ...) (any, error)
- func WithContext(ctx context.Context, tp *inspectionmetadata.TaskProgressMetadata) context.Context
- func WithTitle(title string) coretask.LabelOpt
- type RatioTracker
- type RatioUpdateOption
- type Tracker
- type TrackerOption
Constants ¶
This section is empty.
Variables ¶
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 ¶
func FromContext(ctx context.Context) *inspectionmetadata.TaskProgressMetadata
FromContext retrieves the TaskProgressMetadata bound to the context, returning a no-op instance if absent.
func Report ¶
Report updates the task progress completion ratio (0.0 to 1.0) and message directly from context.
func ReportIndeterminate ¶
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 ¶
func WithContext(ctx context.Context, tp *inspectionmetadata.TaskProgressMetadata) context.Context
WithContext embeds a TaskProgressMetadata instance into the provided context.
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.
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".