Files
lckt-server/initialize/timer.go

40 lines
1001 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package initialize
import (
"fmt"
"git.echol.cn/loser/lckt/task"
"github.com/robfig/cron/v3"
"git.echol.cn/loser/lckt/global"
)
func Timer() {
go func() {
var option []cron.Option
option = append(option, cron.WithSeconds())
// 清理DB定时任务
_, err := global.GVA_Timer.AddTaskByFunc("ClearDB", "@daily", func() {
err := task.ClearTable(global.GVA_DB) // 定时任务方法定在task文件包中
if err != nil {
fmt.Println("timer error:", err)
}
}, "定时清理数据库【日志,黑名单】内容", option...)
if err != nil {
fmt.Println("add timer error:", err)
}
// 其他定时任务定在这里 参考上方使用方法
_, err = global.GVA_Timer.AddTaskByFunc("ClearVip", "@daily", func() {
err2 := task.CheckVip(global.GVA_DB)
if err2 != nil {
fmt.Println("清理过期VIP定时任务失败:", err2)
}
}, "定时清理过期VIP日志内容", option...)
if err != nil {
fmt.Println("add timer error:", err)
}
}()
}