workerbase

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2019 License: MIT Imports: 8 Imported by: 0

README

Nacelle Base Worker Process GoDoc CircleCI Coverage Status

Abstract worker process for nacelle.


Usage

The supplied process is an abstract busy-loop whose behavior is determined by a supplied WorkerSpec interface. This interface has an Init method that receives application config and a Tick method where each phase of work should be done. The tick method is passed a context that will be canceled on shutdown so that any long-running work can be cleanly abandoned. There is an example included in this repository.

  • WithTagModifiers registers the tag modifiers to be used when loading process configuration (see below). This can be used to change the default tick interval, or prefix all target environment variables in the case where more than one worker process is registered per application.
Configuration

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

Environment Variable Default Description
WORKER_STRICT_CLOCK false Subtract the duration of the previous tick from the time between calls to the spec's tick function.
WORKER_TICK_INTERVAL 0 The time (in seconds) between calls to the spec's tick function.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	StrictClock           bool `env:"worker_strict_clock"`
	RawWorkerTickInterval int  `env:"worker_tick_interval" 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:"services"`
	Health   nacelle.Health           `service:"health"`
	// contains filtered or unexported fields
}

func NewWorker

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

func (*Worker) Init

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

func (*Worker) Start

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

func (*Worker) Stop

func (w *Worker) Stop() error

type WorkerSpec

type WorkerSpec interface {
	Init(nacelle.Config) error
	Tick(ctx context.Context) error
}

Jump to

Keyboard shortcuts

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