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.

38 lines
872 B
Go

package initialize
import (
"fmt"
"pychr/task"
"github.com/robfig/cron/v3"
"pychr/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("定时任务标识", "corn表达式", func() {
// 具体执行内容...
// ......
// }, option...)
// if err != nil {
// fmt.Println("add timer error:", err)
// }
}()
}