jobmanager

package module
v0.0.0-...-382e3df Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2017 License: MIT Imports: 8 Imported by: 2

README

jobmanager

Go Documentation

CircleCI

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DoNothingWithErrorsHandler

type DoNothingWithErrorsHandler struct{}

DoNothingWithErrorsHandler does nothing with error values

var DoNothingWithErrors DoNothingWithErrorsHandler

DoNothingWithErrors is the default error handler if none is provided.

func (DoNothingWithErrorsHandler) HandleError

func (dnwe DoNothingWithErrorsHandler) HandleError(err error) error

HandleError does nothing

type ErrorHandler

type ErrorHandler interface {
	HandleError(error) error
}

ErrorHandler is an interface that can process errors.

type Job

type Job struct {
	Name                     string
	Job                      func(context.Context, ...interface{}) error
	Retries                  uint
	RetryableErrors          []error
	RetryableErrorSubstrings []string
	RetryFunc                RetryFunc
	Logger                   interface {
		Printf(message string, args ...interface{})
	}
	ErrorHandler ErrorHandler
}

Job specifies the type of job JobManager can execute. A Job can be customized to have retry behavior.

func (*Job) ProcessJob

func (j *Job) ProcessJob(ctx context.Context, args ...interface{}) error

ProcessJob processes a Job taking into account the retry behavior.

type JobManager

type JobManager struct {
	sync.Mutex

	// Options
	Identifier   string
	Concurrency  uint
	Logger       *log.Logger
	ErrorHandler ErrorHandler
	// contains filtered or unexported fields
}

JobManager handles the concurrent execution of jobs.

func New

func New(options ...func(*JobManager)) *JobManager

New creates a new JobManager.

func (*JobManager) AddJob

func (m *JobManager) AddJob(j *Job, args ...interface{})

AddJob adds a Job to the Job manager.

func (*JobManager) Err

func (m *JobManager) Err() error

Err returns the all of the errors resulting from the execution of all jobs.

func (*JobManager) Printf

func (m *JobManager) Printf(message string, args ...interface{})

Printf logs to the JobManager's logger.

func (*JobManager) Run

func (m *JobManager) Run(ctx context.Context)

Run executes all jobs, waiting for them to complete.

type RetryFunc

type RetryFunc func(context.Context, uint)

RetryFunc customizes the job behavior that's performed in between retries.

var DoNothing RetryFunc = func(_ context.Context, _ uint) {}

DoNothing is a RetryFunc that does nothing in between retries.

var ExponentialBackoff RetryFunc = func(ctx context.Context, retryNum uint) {
	select {
	case <-time.After((1 << retryNum) * time.Second):
	case <-ctx.Done():
	}
}

ExponentialBackoff is a RetryFunc that waits an exponentially increasing amount of time in between retries.

Jump to

Keyboard shortcuts

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