Package worker adding the abstraction layer around background jobs, allows make a job periodically, observe execution time and to control concurrent execution.
Group of workers allows to control jobs start time and wait until all runned workers finished when we need stop all jobs.
- Scheduling, use one from existing
workers.By*
schedule functions. Supporting cron schedule spec format by robfig/cron parser. - Graceful stop, wait until all running jobs was completed.
wg := workers.NewGroup(context.Background())
wg.Add(
workers.
New(func(context.Context) {}).
ByTicker(time.Second),
workers.
New(func(context.Context) {}).
ByTimer(time.Second),
workers.
New(func(context.Context) {}).
ByCronSpec("@every 1s"),
)
wg.Run()
See more examples here