1
0

test_cron_runner.go 638 B

123456789101112131415161718192021222324252627
  1. package TestCode
  2. import (
  3. "github.com/robfig/cron/v3"
  4. "time"
  5. )
  6. func CronRunner() {
  7. cronInstance := cron.New(cron.WithChain(cron.DelayIfStillRunning(cron.DefaultLogger)))
  8. cronInstance.AddFunc("@every 2s", func() {
  9. println(time.Now().Format("2006-01-02 15:04:05"), "cron runner A Start")
  10. time.Sleep(5 * time.Second)
  11. println(time.Now().Format("2006-01-02 15:04:05"), "cron runner A End")
  12. })
  13. cronInstance.AddFunc("@every 5s", func() {
  14. println(time.Now().Format("2006-01-02 15:04:05"), "cron runner B Start")
  15. println(time.Now().Format("2006-01-02 15:04:05"), "cron runner B End")
  16. })
  17. cronInstance.Start()
  18. select {}
  19. }