Shigoto - Task Scheduling
Shigoto is a task scheduling for Golang with friendly API. Shigoto used MongoDB for persistent storage and used Cron format to set the schedule.
Installation
go get github.com/KodepandaID/shigoto
Example Usage
Init
package main
import "github.com/KodepandaID/shigoto"
func main() {
client, e := shigoto.New(&shigoto.Config{
DB: "mongodb://localhost:27017",
DBName: "jobs-scheduler",
Timezone: "Asia/Jakarta",
})
if e != nil {
log.Fatal(e)
}
client.Run()
}
Register a function to call
func main() {
client, e := shigoto.New(&shigoto.Config{
DB: "mongodb://localhost:27017",
DBName: "jobs-scheduler",
Timezone: "Asia/Jakarta",
})
if e != nil {
log.Fatal(e)
}
client.Register("hello", hello)
client.Register("hello-params", helloParams, "message here")
client.Run()
}
func hello() error {
return nil
}
func helloParams(message string) error {
return nil
}
Set Job
For more scheduling information, you can read at Go References.
func main() {
client, e := shigoto.New(&shigoto.Config{
DB: "mongodb://localhost:27017",
DBName: "jobs-scheduler",
Timezone: "Asia/Jakarta",
})
if e != nil {
log.Fatal(e)
}
client.Register("hello", hello)
if _, e := client.
Command("job-name-here", "hello").
EveryMinute().Do(); e != nil {
log.Fatal(e)
}
client.Run()
}
func hello() error {
return nil
}
Remove a Job
func main() {
client, e := shigoto.New(&shigoto.Config{
DB: "mongodb://localhost:27017",
DBName: "jobs-scheduler",
Timezone: "Asia/Jakarta",
})
if e != nil {
log.Fatal(e)
}
client.Register("hello", hello)
client.Delete("hello")
client.Run()
}
License
Copyright Yudha Pratama Wicaksana, Licensed under MIT.