timer.go 849 B

1234567891011121314151617181920212223242526272829
  1. package initialize
  2. import (
  3. "fmt"
  4. "github.com/flipped-aurora/gin-vue-admin/server/config"
  5. "github.com/flipped-aurora/gin-vue-admin/server/global"
  6. "github.com/flipped-aurora/gin-vue-admin/server/utils"
  7. "go.uber.org/zap"
  8. )
  9. func Timer() {
  10. if global.GVA_CONFIG.Timer.Start {
  11. go func() {
  12. global.GVA_Timer.AddTaskByFunc("UnitIntegralSum", "@every 1m", func() {
  13. global.GVA_LOG.Error("timer UnitIntegralSum:", zap.Any("time", 111111))
  14. })
  15. }()
  16. for i := range global.GVA_CONFIG.Timer.Detail {
  17. go func(detail config.Detail) {
  18. global.GVA_Timer.AddTaskByFunc("ClearDB", global.GVA_CONFIG.Timer.Spec, func() {
  19. err := utils.ClearTable(global.GVA_DB, detail.TableName, detail.CompareField, detail.Interval)
  20. if err != nil {
  21. fmt.Println("timer error:", err)
  22. }
  23. })
  24. }(global.GVA_CONFIG.Timer.Detail[i])
  25. }
  26. }
  27. }