Created
October 21, 2019 19:49
-
-
Save chris001177/ffbe3b083ec2112dd76146a50c16fc64 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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