pool

package
v1.1.24 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2024 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Overview

Package pool contains a generic implementation of the worker pool pattern for concurrent processing

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChartReleaseSummarizerOptions added in v1.1.11

type ChartReleaseSummarizerOptions struct {
	Enabled  bool
	Interval time.Duration
	Do       func(map[string]string) error
}

type Job

type Job struct {
	// Name is a short text description for this job to use in log messages
	Name string
	// ChartReleaseName is an optional full name of the chart release as understood
	// by Sherlock (in other words, the canonical globally-unique name for the
	// chart release, like "leonardo-dev"). This must be set for the job to be
	// summarized by a configured ChartReleaseSummarizer.
	ChartReleaseName string
	// Run function that performs work
	Run func(StatusReporter) error
	// Labels optional set of metric labels to add to job metrics
	Labels map[string]string
}

Job a unit of work that can be executed by a Pool

type LogSummarizerOptions added in v1.1.8

type LogSummarizerOptions struct {
	// Enabled if true, print a periodic summary of pool status while items are being processed. For example:
	//
	// 2/5 items processed queued=1 running=2 success=1 error=1
	// foo:    error   err="something bad happened" dur=2m30s
	// bar:    running status="downloading file" dur=30s
	// baz:    running status="uploading file" dur=1m53s
	// quux:   queued
	// blergh: success status="finished transfer"
	//
	Enabled bool
	// Interval how frequently summary messages should be printed to the log
	Interval time.Duration
	// LogLevel level at which summary messages should be logged
	LogLevel zerolog.Level
	// WorkDescription description to use in summary header (defaults to "items processed")
	WorkDescription string
	// Footer an optional footer string to include after printing the summary
	Footer string
	// MaxLineItems an optional number of maximum line items to include in the summary
	MaxLineItems int
	// contains filtered or unexported fields
}

type MetricsOptions added in v1.0.20

type MetricsOptions struct {
	// Enabled if true, record metrics
	Enabled bool
	// PoolName optional name prefix for job metrics
	PoolName string
}

type Option

type Option func(*Options)

Option function for configuring Options

type Options

type Options struct {
	// NumWorkers number of jobs to execute concurrently
	NumWorkers int
	// StopProcessingOnError whether to stop processing work items in the event a job returns an error
	StopProcessingOnError bool
	// LogSummarizer options for printing periodic processing summaries to the log
	LogSummarizer LogSummarizerOptions
	// ChartReleaseSummarizer can be optionally set to if the jobs statuses are chart release
	// statuses that should be further summarized/reported. Note that only Jobs with a
	// ChartReleaseName set will be summarized in this way.
	ChartReleaseSummarizer ChartReleaseSummarizerOptions
	// Metrics options for recording metrics
	Metrics MetricsOptions
}

type Phase added in v1.0.8

type Phase int64

Phase is an enum type representing the execution phase of a work item

const (
	Queued Phase = iota
	Running
	Success
	Error
)

func (Phase) String added in v1.0.8

func (p Phase) String() string

type Pool

type Pool interface {
	// Execute starts execution of the pool, returning an error that aggregates errors from all jobs (if any were encountered)
	Execute() error
	// NumWorkers returns the number of workers in the pool
	NumWorkers() int
}

Pool implements the worker pool pattern for concurrent processing

func New

func New(jobs []Job, options ...Option) Pool

type Status added in v1.0.8

type Status struct {
	// Message a short message summarizing job status
	Message string
	// Context contextual field to add to status summary in log messages
	Context map[string]interface{}
}

Status is for representing job status in log messages

func (Status) Dict added in v1.0.8

func (s Status) Dict() *zerolog.Event

Dict returns a representation of this Status as a zerolog Dict for inclusion in log messages

type StatusReporter added in v1.0.8

type StatusReporter interface {
	// Update report a job status update
	Update(status Status)
}

StatusReporter is an interface for reporting job status updates in logs. Note that its use is _optional_ -- a job's Run() function is free to ignore it.

Jump to

Keyboard shortcuts

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