feat: 添加定时系统

- 实现定时任务
This commit is contained in:
2026-03-26 22:59:58 +08:00
parent 858c29a799
commit b0db64bd7b
8 changed files with 126 additions and 9 deletions

View File

@@ -0,0 +1,32 @@
package schedule
import (
"ckwk/internal/ckwk"
"ckwk/pkg/log"
"time"
"github.com/robfig/cron/v3"
"go.uber.org/zap"
)
func StartCron(m *ckwk.SessionManager) {
loc, _ := time.LoadLocation("Asia/Singapore")
c := cron.New(
cron.WithLocation(loc),
)
// 每天 6 点执行
_, err := c.AddFunc("0 2 * * *", func() {
log.Info("开始定时清理 Session")
m.ClearAll()
})
if err != nil {
log.Error("cron 添加任务失败", zap.Error(err))
return
}
c.Start()
}