autoTask.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package service
  2. import (
  3. "github.com/robfig/cron/v3"
  4. log "github.com/sirupsen/logrus"
  5. "time"
  6. "youngee_b_api/db"
  7. )
  8. func AutoTask() error {
  9. c := cron.New(cron.WithSeconds())
  10. //spec := "0 * */10 * * ?" //cron表达式,每半小时执行一次
  11. //_, err1 := c.AddFunc(spec, AutoTaskUpdateStatus)
  12. //if err1 != nil {
  13. // log.Println("service [AutoTaskUpdateStatus] error:", err1)
  14. // return err1
  15. //}
  16. //_, err2 := c.AddFunc("@midnight", AutoTaskUpdateApplyTimes)
  17. //if err2 != nil {
  18. // log.Println("service [AutoTaskUpdateApplyTimes] error:", err2)
  19. // return err2
  20. //}
  21. //_, err3 := c.AddFunc(spec, AutoTaskCompleteSelection)
  22. //if err3 != nil {
  23. // log.Println("service [AutoTaskCompleteSecTask] error:", err2)
  24. // return err3
  25. //}
  26. c.Start()
  27. return nil
  28. }
  29. func AutoTaskUpdateStatus() {
  30. err := db.AutoUpdateStatus()
  31. log.Println("AutoTaskUpdateStatus is running ,Time :", time.Now())
  32. if err != nil {
  33. log.Println("AutoTaskUpdateStatus error : ", err)
  34. }
  35. }
  36. func AutoTaskUpdateApplyTimes() {
  37. err := db.AutoUpdateApplyTimes()
  38. log.Println("AutoUpdateApplyTimes is running ,Time :", time.Now())
  39. if err != nil {
  40. log.Println("AutoUpdateApplyTimes error : ", err)
  41. }
  42. }
  43. func AutoTaskCompleteSelection() {
  44. err := db.AutoCompleteSelection()
  45. log.Println("AutoUpdateApplyTimes is running ,Time :", time.Now())
  46. if err != nil {
  47. log.Println("AutoUpdateApplyTimes error : ", err)
  48. }
  49. }