Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ErrorWorkerAlreadyExists is returned when a worker is added with a name that already exists. ErrorWorkerAlreadyExists = errors.New("worker already exists") // ErrorWorkerAlreadyRunning is returned when a worker is started that is already running. ErrorWorkerAlreadyRunning = errors.New("worker already running") // ErrorWorkerNotRunning is returned when a worker is stopped that is not running. ErrorWorkerNotRunning = errors.New("worker not running") // ErrorWorkerNotFound is returned when a worker is stopped that doesn't exist. ErrorWorkerNotFound = errors.New("worker not found") )
Functions ¶
func NewExponentialBackoff ¶
NewExponentialBackoff returns a function that returns an exponentially increasing duration. The first call to the function will return the start duration. Each subsequent call will double the duration until the max duration is reached. The max duration will be returned for all subsequent calls to the function after the max duration is reached.
Types ¶
type Manager ¶
type Manager interface {
// AddWorker registers a new worker with the given name. If a worker with the
// given name already exists, ErrorWorkerAlreadyExists is returned. The worker
// is not started until StartWorker is called.
AddWorker(string, Worker) error
// Names returns a slice of all registered worker names.
Names() []string
// StartWorker starts the worker with the given name. If the worker is not found,
// ErrorWorkerNotFound is returned. If multiple workers are given, they are
// started in the order given. If any worker fails to start, the error is logged
// and returned and no further workers are started. If any workers were already
// running prior to the error being encountered, they are not stopped. If the
// worker is already running, it is not restarted.
StartWorker(...string) error
// StopWorker stops the worker with the given name and waits for it to stop. If
// the worker is not found, ErrorWorkerNotFound is returned. If multiple workers
// are given, they are stopped in the order given. If any worker fails to stop,
// the error is logged and returned and no further workers are stopped, however
// any workers already in the process of stopping will be waited for.
StopWorker(...string) error
// StopAllWorkers stops all registered workers. This is a convenience method that
// calls StopWorker with all registered worker names. If any worker fails to stop,
// the error is logged and iteration continues to the next worker.
StopAllWorkers()
}
Manager is an interface for managing workers. It provides methods for adding workers, starting and stopping workers, and enumerating registered workers.
func NewManager ¶
func NewManager() Manager
NewManager creates a new Manager instance with no registered workers.
type Worker ¶
type Worker interface {
// Run starts the worker. This method should block until the worker is stopped.
Run() error
// Stop stops the worker. This method should unblock the Run method.
Stop() error
}
Worker is an interface for a worker. It provides methods for starting and stopping the worker.
Click to show internal directories.
Click to hide internal directories.