-
Notifications
You must be signed in to change notification settings - Fork 0
/
cronjobs.go
50 lines (40 loc) · 1.07 KB
/
cronjobs.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package main
import (
"fmt"
"time"
"github.com/robfig/cron/v3"
)
func main() {
fmt.Println("*** CronJob tests started")
fmt.Println("Build Cron")
cronJob := cron.New(
// cron.WithLocation(time.UTC),
cron.WithSeconds(),
)
fmt.Println("Add functions to Cron")
// second | minute | hour | day-of-month | month | day-of-week
cronJob.AddFunc("*/5 * * * * *", execution)
// cronJob.AddFunc("1 * * * * *", execution)
// cronJob.AddFunc("1 * * * * *", execution)
fmt.Println("First Cron start")
cronJob.Start()
// for _, job := range cronJob.Entries() {
// fmt.Printf("cron entryId %d\n", job.ID)
// fmt.Printf("cron next %v\n", job.Next)
// fmt.Printf("cron valid %t\n", job.Valid())
// }
time.Sleep(20 *time.Second)
fmt.Println("First Cron stop")
cronJob.Stop()
time.Sleep(20 *time.Second)
fmt.Println("Second Cron start")
cronJob.Start()
time.Sleep(20 *time.Second)
fmt.Println("Second Cron stop")
cronJob.Stop()
fmt.Println("*** CronJob tests completed")
}
func execution() {
now := time.Now()
fmt.Printf("this is a job execution at %v\n", now)
}