Skip to content

Instantly share code, notes, and snippets.

@gufranmirza
Created June 21, 2019 17:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gufranmirza/3e4d2aed92cba88c17e4fe452edc2695 to your computer and use it in GitHub Desktop.
Save gufranmirza/3e4d2aed92cba88c17e4fe452edc2695 to your computer and use it in GitHub Desktop.
c := cron.New()
c.AddFunc("30 * * * *", func() {
fmt.Println("Every hour on the half hour")
})
c.AddFunc("30 3-6,20-23 * * *", func() {
fmt.Println(".. in the range 3-6am, 8-11pm")
})
c.AddFunc("CRON_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 1h30m", func() {
fmt.Println("Every hour thirty")
})
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") })
..
// Inspect the cron job entries' next and previous run times.
inspect(c.Entries())
..
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