Documentation ¶
Overview ¶
Package bgwork handles background work or jobs distributed over many machines.
TODO: gather ideas - https://blog.gobuffalo.io/buffalo-v0-9-0-released-68fcf0844473 - https://github.com/gocraft/work - https://medium.com/@matryer/introducing-vice-go-channels-across-many-machines-bcac1147d7e2
Index ¶
- func Async(fns ...func() error) <-chan error
- func AutoScaling(ctx context.Context, chanEvents <-chan interface{}, ...)
- func ScheduleWorkAt(ctx context.Context, opts ScheduleOptions, t func() error)
- func Wait(length int, block func(index int))
- func WaitContext(length int, block func(ctx context.Context, index int) error) error
- type ScalingOptions
- type ScheduleOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Async ¶
Async runs the given functions asynchronous. It returns all errors, if there are. The channel gets closed once all functions are done.
func AutoScaling ¶
func AutoScaling(ctx context.Context, chanEvents <-chan interface{}, jobFn func(event interface{}), opt ScalingOptions)
AutoScaling runs the same task across min to max background workers. Idle workers are getting terminated until the min amount of workers get reached. There won't be more workers than max amount. AutoScaling blocks once called so it must start in its own goroutine.
func ScheduleWorkAt ¶
func ScheduleWorkAt(ctx context.Context, opts ScheduleOptions, t func() error)
ScheduleWorkAt runs the task t
Types ¶
type ScalingOptions ¶
type ScalingOptions struct { // MinWorkers defaults to 2 MinWorkers uint16 // MaxWorkers defaults to 16 MaxWorkers uint16 // WorkerCheckInterval defaults to one second. Duration when to check for // termination and/or creation of workers. Each interval the GetStatistics // function will be called. WorkerCheckInterval time.Duration // GetStatistics gets called each WorkerCheckInterval GetStatistics func(string) }
ScalingOptions sets various configurations to AutoScaling function.