-
-
Notifications
You must be signed in to change notification settings - Fork 130
/
Copy pathscheduler.go
33 lines (23 loc) · 818 Bytes
/
scheduler.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package main
import (
"fmt"
"time"
"github.com/robfig/cron/v3"
)
func main() {
c := cron.New()
// Funcs are automatically invoked in their own goroutine, asynchronously
c.AddFunc("0 30 * * * *", func() { fmt.Println("Every hour on the half hour") })
c.AddFunc("TZ=America/New_York 30 04 * * * *", func() { fmt.Println("Runs at 04:30 New York time every day") })
c.AddFunc("@hourly", func() { fmt.Println("Runs every hour") })
c.AddFunc("@every 0h0m1s", func() { sayHelloTo("Someone!") })
c.Start()
// 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)
}
func sayHelloTo(name string) {
fmt.Println("Hello ", name)
}