workers

package
v0.0.0-...-64bf489 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2024 License: Apache-2.0 Imports: 4 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 struct {
	Context     context.Context
	Duration    time.Duration
	Handler     func(context.Context, *map[string]interface{}) error
	HandlerArgs *map[string]interface{}
}

Job contains all of the information for a worker to execute the job. A job contains a context and a duration. The job handler is provided a new context for the job based off or the job's provided context and the given duration.

type Workers

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

Workers handles the provided number of workers and allows jobs to be sent to the workers and distributes those jobs to the workers.

func NewWorkers

func NewWorkers() *Workers

NewWorkers initializes a QueueWorkers structure.

func (*Workers) Add

func (w *Workers) Add(job *Job) error

Add takes a Job as an argument and sends that job to the workers to be executed when a worker is available.

func (*Workers) Start

func (w *Workers) Start(ctx context.Context, numWorkers int, errs chan error) error

Start creates the number of workers provided. It also runs using a context. If the context ends, a signal is sent to each worker to stop working after they have completed their latest job. Start throws an error if Workers have already been started and has not been stopped.

func (*Workers) Stop

func (w *Workers) Stop() error

Stop sends a stop signal to all of the workers to stop accepting jobs and to close. Stop throws an error if QueueWorkers has already been stopped and has not been restarted.

Jump to

Keyboard shortcuts

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