kronk is dead simple scheduler for modern scalable systems.
It allows you to manage background tasks in a distributed architecture.
Already supports Redis as distributed lock manager.
So, now you can add jobs and be sure that they will be completed on only one instance.
go get -u github.com/utkonos-dev/kronk
import (
"github.com/utkonos-dev/kronk"
redisAdapter "github.com/utkonos-dev/kronk/dlm/redis"
"github.com/utkonos-dev/kronk/scheduler/cron"
)
k := kronk.New(
redisAdapter.NewLocker(redisConn),
cron.NewScheduler(),
logger,
kronk.Config{
DefaultLockExp: time.Second,
},
)
k.Start()
AddJob can be safely called on all instances, but the job will be performed only by one.
job := func() {
fmt.Println("That'll work")
}
err := k.AddRegularJob("kronksays", "* * * * *", job)
if err != nil {
// ...
}