You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
785 B
Go

11 months ago
package initialize
import (
"fmt"
"github.com/robfig/cron/v3"
"miniapp/config"
"miniapp/global"
"miniapp/utils"
)
func Timer() {
if global.GVA_CONFIG.Timer.Start {
for i := range global.GVA_CONFIG.Timer.Detail {
go func(detail config.Detail) {
var option []cron.Option
if global.GVA_CONFIG.Timer.WithSeconds {
option = append(option, cron.WithSeconds())
}
_, err := global.GVA_Timer.AddTaskByFunc("ClearDB", global.GVA_CONFIG.Timer.Spec, func() {
err := utils.ClearTable(global.GVA_DB, detail.TableName, detail.CompareField, detail.Interval)
if err != nil {
fmt.Println("timer error:", err)
}
}, option...)
if err != nil {
fmt.Println("add timer error:", err)
}
}(global.GVA_CONFIG.Timer.Detail[i])
}
}
}