Skip to content

Instantly share code, notes, and snippets.

@chris001177
Created October 21, 2019 19:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chris001177/ffbe3b083ec2112dd76146a50c16fc64 to your computer and use it in GitHub Desktop.
Save chris001177/ffbe3b083ec2112dd76146a50c16fc64 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"gopkg.in/robfig/cron.v2"
"time"
)
func main() {
c := cron.New()
c.AddFunc("0 30 * * * *", func() { fmt.Println("Every hour on the half hour") })
c.AddFunc("TZ=Asia/Tokyo 30 04 * * * *", func() { fmt.Println("Runs at 04:30 Tokyo time every day") })
c.AddFunc("@hourly", func() { fmt.Println("Every hour") })
c.AddFunc("@every 0h0m1s", func() { fmt.Println("Every second") })
c.Start()
// Funcs are invoked in their own goroutine, asynchronously.
// Funcs may also be added to a running Cron
c.AddFunc("@daily", func() { fmt.Println("Every day") })
// Added time to see output
time.Sleep(10 * time.Second)
c.Stop() // Stop the scheduler (does not stop any jobs already running).
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment