Documentation
¶
Index ¶
- Variables
- type Director
- type DirectorOption
- type TimeoutMiddleware
- type Worker
- type WorkerParameter
- func Every(duration time.Duration) WorkerParameter
- func Id(id string) WorkerParameter
- func IgnoreWorkerErrors(ignore bool) WorkerParameter
- func Infinitely() WorkerParameter
- func Next(ids ...string) WorkerParameter
- func NotifyError(errCh chan<- error) WorkerParameter
- func PanicOnError(p bool) WorkerParameter
- func Repeat(n int) WorkerParameter
- func TriggerOn(channels ...<-chan interface{}) WorkerParameter
- func WithArgs(args ...interface{}) WorkerParameter
- func WithContext(ctx context.Context) WorkerParameter
- func WithDelay(duration time.Duration) WorkerParameter
- func WithDelayFunc(delayFunc func(last time.Time) time.Duration) WorkerParameter
- type WorkplaceStatus
Constants ¶
This section is empty.
Variables ¶
var ( DirectorAlreadyWorks = errors.New("director is working already") DirectorNotWorks = errors.New("director is not working yet") )
var TimeoutError = errors.New("execution timeout")
Functions ¶
This section is empty.
Types ¶
type Director ¶
type Director struct {
// contains filtered or unexported fields
}
The main figure in working process.
func NewDirector ¶
func NewDirector(options ...DirectorOption) *Director
NewDirector creates director, which observes workers. Director may take some options
func (*Director) Begin ¶
func (d *Director) Begin(params ...WorkerParameter)
Begin begins workers executions. Panics, when call on already working director.
type DirectorOption ¶
type DirectorOption func(*directorOptions)
Generic option for director.
func WithIdGenerator ¶
func WithIdGenerator(generator func() string) DirectorOption
WithIdGenerator sets generator function that should generate unique ids for workers, when id for worker not set directly.
type TimeoutMiddleware ¶
type TimeoutMiddleware struct {
// contains filtered or unexported fields
}
func NewWorkerTimeout ¶
func NewWorkerTimeout(next Worker, timeout time.Duration) *TimeoutMiddleware
type Worker ¶
Worker is an instance that should do some work. It takes execution context and any amount of arguments and returns any amount of results and error. Arguments comes from triggers or executions of previous worker in chain.
type WorkerParameter ¶
type WorkerParameter func(*workerParams)
Generic parameter for worker.
func Every ¶
func Every(duration time.Duration) WorkerParameter
Every adds duration to ticker list. Each Every applied as OR, so Every(time.Second), Every(time.Second*2) will start one worker each second and two workers each two seconds.
func IgnoreWorkerErrors ¶
func IgnoreWorkerErrors(ignore bool) WorkerParameter
IgnoreWorkerErrors sets flag, that continues worker execution if error was occurred.
False by default.
func Next ¶
func Next(ids ...string) WorkerParameter
Next adds worker names to 'next' list. After execution main worker director concurrently executes all workers in list with provided arguments taken from main worker results.
func NotifyError ¶
func NotifyError(errCh chan<- error) WorkerParameter
NotifyError sends error to channel provided channel if any was occurred.
func PanicOnError ¶
func PanicOnError(p bool) WorkerParameter
PanicOnError sets panic flag. if error was occurred, director will panic.
False by default.
func Repeat ¶
func Repeat(n int) WorkerParameter
Repeat sets amount of executions for worker. For negative values of `n` worker will executes infinitely. 0 by default.
func TriggerOn ¶
func TriggerOn(channels ...<-chan interface{}) WorkerParameter
TriggerOn adds channels to subscribe list. Execute worker, when something received from any channel.
func WithArgs ¶
func WithArgs(args ...interface{}) WorkerParameter
WithArgs sets args for first worker execution. nil by default.
func WithContext ¶
func WithContext(ctx context.Context) WorkerParameter
WithContext sets worker execution context. Director looks at context.Done() and when it triggers, director stops all new worker executions. It does not stops currently working workers, which were stated as next element in chain execution by Next() declaration. In this case, you should stop it by yourself.
context.Background by default.
func WithDelay ¶
func WithDelay(duration time.Duration) WorkerParameter
WithDelay sets constant delay for loop executions. 0 by default.
func WithDelayFunc ¶
func WithDelayFunc(delayFunc func(last time.Time) time.Duration) WorkerParameter
WithDelayFunc sets delay rule for loop executions.
type WorkplaceStatus ¶
type WorkplaceStatus struct {
// contains filtered or unexported fields
}
func NewWorkerStatus ¶
func NewWorkerStatus(next Worker) *WorkplaceStatus
func (*WorkplaceStatus) Busy ¶
func (s *WorkplaceStatus) Busy() bool
func (*WorkplaceStatus) Status ¶
func (s *WorkplaceStatus) Status() (working, executed uint64)