TimeTask.go 439 B

123456789101112131415161718192021
  1. package TimeTask
  2. import (
  3. "PublishCode/logs"
  4. "PublishCode/models"
  5. "fmt"
  6. "github.com/robfig/cron/v3"
  7. )
  8. func TimeTaskGo() {
  9. logs.Println("==========定时任务开始==========")
  10. crontab := cron.New(cron.WithSeconds())
  11. _, err := crontab.AddFunc("0 0 0 * * *", models.PublishCode_Indexes)
  12. if err != nil {
  13. fmt.Printf("err: %v\n", err)
  14. logs.Println("Cron [models.PublishCode_Indexes] OK!")
  15. }
  16. crontab.Start() // 开始任务
  17. }