timer.go 635 B

123456789101112131415161718192021222324
  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. )
  8. func Timer() {
  9. if global.GVA_CONFIG.Timer.Start {
  10. for _, detail := range global.GVA_CONFIG.Timer.Detail {
  11. go func(detail config.Detail) {
  12. global.GVA_Timer.AddTaskByFunc("ClearDB", global.GVA_CONFIG.Timer.Spec, func() {
  13. err := utils.ClearTable(global.GVA_DB, detail.TableName, detail.CompareField, detail.Interval)
  14. if err != nil {
  15. fmt.Println("timer error:", err)
  16. }
  17. })
  18. }(detail)
  19. }
  20. }
  21. }