mirror of
https://gitee.com/johng/gf.git
synced 2024-12-05 05:37:55 +08:00
29 lines
788 B
Go
29 lines
788 B
Go
package main
|
|
|
|
import (
|
|
"github.com/gogf/gf/g/os/gcron"
|
|
"github.com/gogf/gf/g/os/glog"
|
|
"time"
|
|
)
|
|
|
|
func main() {
|
|
gcron.Add("0 30 * * * *", func() { glog.Println("Every hour on the half hour") })
|
|
gcron.Add("* * * * * *", func() { glog.Println("Every second, pattern") }, "second-cron")
|
|
gcron.Add("*/5 * * * * *", func() { glog.Println("Every 5 seconds, pattern") })
|
|
|
|
gcron.Add("@hourly", func() { glog.Println("Every hour") })
|
|
gcron.Add("@every 1h30m", func() { glog.Println("Every hour thirty") })
|
|
gcron.Add("@every 1s", func() { glog.Println("Every 1 second") })
|
|
gcron.Add("@every 5s", func() { glog.Println("Every 5 seconds") })
|
|
|
|
time.Sleep(3 * time.Second)
|
|
|
|
gcron.Stop("second-cron")
|
|
|
|
time.Sleep(3 * time.Second)
|
|
|
|
gcron.Start("second-cron")
|
|
|
|
time.Sleep(10 * time.Second)
|
|
}
|