workers

package
v0.0.0-...-f0cd508 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2020 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrWrongConfig = errBase("configure error")

	// ErrEmptyConfig when viper not passed to params
	ErrEmptyConfig = fmt.Errorf("%w; empty config", ErrWrongConfig)

	// ErrEmptyWorkers when workers not passed to params
	ErrEmptyWorkers = fmt.Errorf("%w; empty workers", ErrWrongConfig)

	// ErrEmptyLocker when locker required,
	// but not passed to params
	ErrEmptyLocker = fmt.Errorf("%w; empty locker", ErrWrongConfig)

	// ErrEmptyJob when worker job is nil
	ErrEmptyJob = fmt.Errorf("%w; empty job", ErrWrongConfig)

	// ErrCreateWorker when cannot create worker
	ErrCreateWorker = errBase("cannot create worker")
)
View Source
var Module = module.Module{
	{Constructor: NewWorkersGroup},
}

Module of workers

Functions

This section is empty.

Types

type Config

type Config struct {
	Cron        string
	Disabled    bool
	Immediately bool
	Timer       time.Duration
	Ticker      time.Duration
}

type ConfigWorkers

type ConfigWorkers map[string]Config

type Group

type Group interface {
	Add(Option) error
	Run()
	Stop()
	Wait(context.Context) error
}

func NewWorkersGroup

func NewWorkersGroup(p Params) (Group, error)

NewWorkersGroup returns workers group with injected workers

type Job

type Job func(context.Context)

type Locker

type Locker interface {
	Lock() error
	Unlock()
}

Locker interface

type Option

type Option struct {
	Name   string
	Job    Job
	Config Config
	Locker Locker
}

type Params

type Params struct {
	dig.In

	Context context.Context
	Workers Workers
	Jobs    map[string]Job
	Config  ConfigWorkers `optional:"true"`
	Locker  Locker        `optional:"true"`
}

Params is dependencies for create workers slice

type Workers

type Workers interface {
	Group(context.Context) Group
}

Jump to

Keyboard shortcuts

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