feat: 添加定时系统
- 实现定时任务
This commit is contained in:
32
internal/schedule/schedule.go
Normal file
32
internal/schedule/schedule.go
Normal 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()
|
||||
}
|
||||
Reference in New Issue
Block a user