main.go 1009 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package main
  2. import (
  3. "github.com/robfig/cron"
  4. "log"
  5. "resourceBrushLibrary/config"
  6. "resourceBrushLibrary/entity"
  7. "time"
  8. )
  9. func main() {
  10. go (&entity.LimitTimeActivity{}).Run()
  11. go (&entity.Adp{}).Run()
  12. go (&entity.Point{}).Run()
  13. go MinTask()
  14. //go MonthlyTask()
  15. <-chan bool(nil)
  16. }
  17. // 每月执行
  18. func MonthlyTask() {
  19. log.Println(time.Now())
  20. c := cron.New()
  21. // 添加要执行的任务
  22. c.AddFunc(config.Config.MonthlyTask, func() {
  23. // 执行任务的代码
  24. now := time.Now()
  25. endTime := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location()).AddDate(0, 1, -1).Format("2006-01-02")
  26. entity.PersonResource(endTime)
  27. entity.EntResource(endTime)
  28. })
  29. // 启动Cron调度器
  30. c.Start()
  31. select {}
  32. }
  33. // 每分钟执行
  34. func MinTask() {
  35. //entity.OrderResource()
  36. log.Println(time.Now())
  37. c := cron.New()
  38. // 添加要执行的任务
  39. c.AddFunc(config.Config.MinTask, func() {
  40. // 执行任务的代码
  41. entity.OrderResource()
  42. })
  43. // 启动Cron调度器
  44. c.Start()
  45. select {}
  46. }