0%

Golang 常用定时任务

Example 1

1
2
3
4
5
6
func Task300() {
for {
time.Sleep(300 * time.Second)
run_task()
}
}

Example 2

1
2
3
4
5
6
7
8
9
10
11
func Task300() {
rand.Seed(time.Now().UnixNano())
n := rand.Intn(300)
time.Sleep(time.Duration(n) * time.Second)
ticker := time.NewTicker(time.Duration(300) * time.Second)
defer ticker.Stop()
for {
<-ticker.C
run_task()
}
}

grinning all the time

😄 😄 😄 😄 😄 😄 😄 😄 😄 😄 😄 😄 😄 😄 😄 😄 😄 😄 😄 😄 😄