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 Job ¶
type Job struct { // Name short text description for this job to use in log messages Name string // Run function that performs work Run func(StatusReporter) error }
Job a unit of work that can be executed by a Pool
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 // Summarizer options for printing periodict processing summaries to the log Summarizer SummarizerOptions }
type Phase ¶ added in v1.0.8
type Phase int64
Phase is an enum type representing the execution phase of a work item
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
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
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.
type SummarizerOptions ¶ added in v1.0.8
type SummarizerOptions 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" duration=2m30s // bar: running status="downloading file" duration=30s // baz: running status="uploading file" duration=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 string // MaxLineItems an optional number of maximum line items to include in the summary MaxLineItems int // contains filtered or unexported fields }
Click to show internal directories.
Click to hide internal directories.