jobs

package
v0.0.0-...-b7aacc1 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2023 License: Apache-2.0 Imports: 5 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Job

type Job func(ctx context.Context) error

Job represents a (long-running) process that can be spawned on a separate go-routine. When encountering an error, a Job should send that error to the given channel and continue to run.

type JobManager

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

JobManager manages multiple concurrent jobs and handles their errors. Can wait for all jobs and error handling to finish.

func NewMgr

func NewMgr(ctx context.Context, opts ...MgrOptions) *JobManager

NewMgr returns a new JobManager

func (*JobManager) AddJob

func (mgr *JobManager) AddJob(j Job)

AddJob spawns a new goroutine for the given job, manages its lifetime and handles its errors

func (*JobManager) AddJobs

func (mgr *JobManager) AddJobs(jobs ...Job)

AddJobs calls AddJob for each of the given jobs

func (*JobManager) Done

func (mgr *JobManager) Done() <-chan struct{}

Done returns a channel that gets closed when all jobs finished

func (*JobManager) Errs

func (mgr *JobManager) Errs() <-chan error

Errs returns errors encountered during job execution

type MgrOptions

type MgrOptions func(*JobManager) *JobManager

MgrOptions modify the behaviour of the JobManager

func WithErrorCacheCapacity

func WithErrorCacheCapacity(cap int64) MgrOptions

WithErrorCacheCapacity defines the size of the error cache. If the cache is full new errors from jobs will be ignored. Default is 1000

func WithMaxCapacity

func WithMaxCapacity(cap int64) MgrOptions

WithMaxCapacity defines how many jobs will be run in parallel

Jump to

Keyboard shortcuts

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