schedule
schedule copied to clipboard
Go-based Task Scheduling System
Schedule
Schedule is a small library that helps you specify recurring tasks in a cronjob-like interface (without actually using cron's syntax). It is heavily inspired by Laravel's Task Scheduling and uses cronexpr for the heavy lifting.
Install
I recommend dep for dependency management:
dep ensure -add github.com/bastiankoetsier/schedule
Usage
// create a base context with cancellation
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
s := &schedule.Schedule{}
// Start returns a channel which you can receive on as soon as the scheduler is shut down
shutDown := s.Start(ctx)
// You can use the helper schedule.RunFunc to wrap any arbitray function to use
s.Command(schedule.RunFunc(func(ctx context.Context) {
fmt.Println("I run every minute", time.Now())
})).EveryMinute()
// You can also chain the specs on when to run:
s.Command(schedule.RunFunc(func(ctx context.Context) {
fmt.Println("I run only mondays, but every fifteen minutes of that weekday", time.Now())
})).Mondays().EveryFifteenMinutes()
Matchers
The chainable matchers can be found on the Entry type.