Scheduler
Go jobs execution system. Inspired by CI/CD and Unity task scheduler.
Created to be used for kyoto lifecycle management, but also can be easily used for other purposes.
Features
- Define job execution groups
- Configure jobs to be dependent on another job or entire group
- Configure workers count
- Simple shortcuts for parallel processing (for, foreach)
Reasons?
Managing jobs with plain Go code is not easy. You need to write a lot of boilerplate code, keep track of dependencies between jobs, manually manage job execution order, and so on. This library is designed to hide all of these complexities under the hood.
Examples
Quick Start
...
func main() {
s := scheduler.New()
s.Workers = 2
// This jobs will be executed in parallel
s.Add(scheduler.Job{
Func: func() error {
log.Println("I'm a job 1")
},
})
s.Add(scheduler.Job{
Func: func() error {
log.Println("I'm a job 2")
},
})
s.Execute()
}
Dependencies
...
func main() {
s := scheduler.New()
s.Workers = 2
// This jobs will be executed in parallel
s.Add(scheduler.Job{
Group: "group0",
Func: func() error {
log.Println("I'm a job 1")
},
})
s.Add(scheduler.Job{
Group: "group0",
Name: "foo",
Func: func() error {
log.Println("I'm a job 2")
},
})
// This job will be executed after all jobs in group0
s.Add(scheduler.Job{
Dependencies: []string{"group0"},
Func: func() error {
log.Println("I'm a job 3")
},
})
// This job will be executed after 'foo' job in group0
s.Add(scheduler.Job{
Dependencies: []string{"group0:foo"},
Func: func() error {
log.Println("I'm a job 4")
},
})
s.Execute()
}
Shortcuts
...
func main() {
// All jobs will be executed in parallel
scheduler.For(10, func(i int) error {
log.Println("I'm a job", i)
})
// All jobs will be executed in parallel
items := []interface{}{"foo", "bar", "baz"}
scheduler.ForEach(items, func(item interface{}) error {
log.Println("I'm a job with", item)
})
}