Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Job ¶
type Job struct { // MaxWorkers is the maximum number of workers processing a batch of tasks in parallel MaxWorkers int // MinWorkers is the minimum number of workers processing a batch of tasks in parallel MinWorkers int // Worker for processing tasks Worker Worker // FailFast controls the behavior of this Job upon errors. If set to true, it will quit // further processing upon the first error that occurs. For fault tolerant applications // use false. FailFast bool }
Job enques assignments for parallel processing and synchronous response
func (*Job) Dispatch ¶
func (j *Job) Dispatch(ctx context.Context, tasks []interface{}) *WorkerError
Dispatch spawns a set of workers processing in parallel the supplied tasks. If the context is cancelled or has timed out (if it's a timeout context), or if any other error occurs during processing of tasks, a workerError error is returned as soon as possible, processing halts and workers are disposed.
type Worker ¶
type Worker interface { // Work processes the task within the given context. Work(ctx context.Context, task interface{}) *WorkerError }
Worker declares workers functional interface
type WorkerError ¶
type WorkerError struct {
// contains filtered or unexported fields
}
WorkerError wraps an underlying error struct and adds optional code to enrich the context of the error e.g. with HTTP status codes
func NewWorkerError ¶
func NewWorkerError(err error, code int) *WorkerError
NewWorkerError creates worker errors
func (WorkerError) Is ¶
func (we WorkerError) Is(target error) bool
Is implements the contract for errors.Is (https://golang.org/pkg/errors/#Is)
type WorkerFunc ¶
type WorkerFunc func(ctx context.Context, task interface{}) *WorkerError
The WorkerFunc type is an adapter to allow the use of ordinary functions as Workers. If f is a function with the appropriate signature, WorkerFunc(f) is a Worker object that calls f.
func (WorkerFunc) Work ¶
func (f WorkerFunc) Work(ctx context.Context, task interface{}) *WorkerError
Work calls f(ctx, Task).