autoTask.go 915 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package service
  2. import (
  3. "time"
  4. "youngee_b_api/db"
  5. "github.com/robfig/cron/v3"
  6. log "github.com/sirupsen/logrus"
  7. )
  8. func AutoTask() error {
  9. c := cron.New()
  10. _, err1 := c.AddFunc("@midnight", AutoTaskUpdateStatus)
  11. if err1 != nil {
  12. log.Println("service [AutoTaskUpdateStatus] error:", err1)
  13. return err1
  14. }
  15. _, err2 := c.AddFunc("@midnight", AutoTaskUpdateApplyTimes)
  16. if err2 != nil {
  17. log.Println("service [AutoTaskUpdateApplyTimes] error:", err2)
  18. return err2
  19. }
  20. c.Start()
  21. return nil
  22. }
  23. func AutoTaskUpdateStatus() {
  24. err := db.AutoUpdateStatus()
  25. log.Println("AutoTaskUpdateStatus is running ,Time :", time.Now())
  26. if err != nil {
  27. log.Println("AutoTaskUpdateStatus error : ", err)
  28. }
  29. }
  30. func AutoTaskUpdateApplyTimes() {
  31. err := db.AutoUpdateApplyTimes()
  32. log.Println("AutoUpdateApplyTimes is running ,Time :", time.Now())
  33. if err != nil {
  34. log.Println("AutoUpdateApplyTimes error : ", err)
  35. }
  36. }