worker

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2020 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// STARTED is a value used for control which are running
	STARTED = "Started"
	// FINISHED is a value used for control which are finished
	FINISHED = "Finished"
	// ERROR is a value used for control if has error
	ERROR = "Error"
)

Variables

This section is empty.

Functions

func RunWorkers

func RunWorkers(workers []*Worker, handleError func(w *Worker, err error)) error

RunWorkers is a function that administrate the workers and yours errors

Types

type SubWorker

type SubWorker struct {
	Worker *Worker
	ID     int
	Status string
	Error  error
}

SubWorker is a type that represents the concurrency, for the number of concurrency has an #SubWorker

func (SubWorker) Name

func (s SubWorker) Name() string

Name return the name of #SubWorker the pattern is %s-%s <- #Worker.Name, #SubWorker.ID

type Worker

type Worker struct {
	ID            string
	Name          string
	StartAt       time.Time
	FinishedAt    time.Time
	Handle        func() error
	Concurrency   int
	RestartAlways bool
	Restarts      int
	// contains filtered or unexported fields
}

Worker is a type that represents an group of concurrency and keep some settings

func NewWorker

func NewWorker(name string, handle func() error, concurrency int, restartAlways bool) *Worker

NewWorker is a constructor for #Worker and give for user some default settings

func (*Worker) IsUp

func (w *Worker) IsUp() bool

IsUp check if anyone #SubWorker still #STARTED, this survey responds if it is running

func (*Worker) Run

func (w *Worker) Run(errors chan WrapperHandleError)

Run is a executed inside goroutine by #RunWorkers He administrate the number of concurrency

func (*Worker) Status

func (w *Worker) Status() map[string]string

Status return a map with status from the each #SubWorker

type WrapperHandleError

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

WrapperHandleError is a wrapper to transport worker and the error generate inside worker

Jump to

Keyboard shortcuts

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