worker

package
v0.0.0-...-19169da Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2019 License: MIT Imports: 6 Imported by: 0

README

Nacelle Base Worker Process

This package contains a base process implementation for a generic worker which performs some work prompted by an external event (e.g. a remote work queue on a schedule).

Usage

To use a worker, initailize a worker by passing a Worker Spec to the NewWorker constructor. A worker spec is an object with an Init method that takes a ncelle config object (as all process initializer methods do) as well as a reference to the worker, and a Tick method. On a timer, the worker will prompt the worker to perform a single unit of work.

The worker spec will have services injected and will receive the nacelle config object on initialization as if it were a process.

To get a better understanding of the full usage, see the example.

Configuration

The default process behavior can be configured by the following environment variables.

Environment Variable Default Description
WORKER_TICK_INTERVAL 0 The duration (in seconds) between calls to the spec's tick method.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	RawWorkerTickInterval int `env:"worker_tick_interval" file:"worker_tick_interval" mask:"true" default:"0"`

	WorkerTickInterval time.Duration
}

func (*Config) PostLoad

func (c *Config) PostLoad() error

type ConfigFunc

type ConfigFunc func(*options)

ConfigFunc is a function used to configure an instance of a Worker.

func WithTagModifiers

func WithTagModifiers(modifiers ...config.TagModifier) ConfigFunc

WithTagModifiers applies the given tag modifiers on config load.

type Worker

type Worker struct {
	Services nacelle.ServiceContainer `service:"container"`
	Health   nacelle.Health           `service:"health"`
	// contains filtered or unexported fields
}

func NewWorker

func NewWorker(spec WorkerSpec, configs ...ConfigFunc) *Worker

func (*Worker) HaltChan

func (w *Worker) HaltChan() <-chan struct{}

func (*Worker) Init

func (w *Worker) Init(config nacelle.Config) error

func (*Worker) IsDone

func (w *Worker) IsDone() bool

func (*Worker) Start

func (w *Worker) Start() error

func (*Worker) Stop

func (w *Worker) Stop() (err error)

type WorkerSpec

type WorkerSpec interface {
	Init(nacelle.Config, *Worker) error
	Tick() error
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳