Initial commit
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
package botser
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"stat/common/enum/consts"
|
||||
"stat/common/log"
|
||||
"stat/common/statutils"
|
||||
"stat/common/tgbot"
|
||||
"stat/common/utils"
|
||||
"stat/statg"
|
||||
"time"
|
||||
|
||||
"github.com/robfig/cron/v3"
|
||||
)
|
||||
|
||||
var (
|
||||
botCron *cron.Cron
|
||||
)
|
||||
|
||||
func init() {
|
||||
botCron = cron.New(cron.WithSeconds(), cron.WithChain(cron.SkipIfStillRunning(&log.Logger{}))) // 秒级定时任务
|
||||
}
|
||||
|
||||
// Start 定时器任务启动
|
||||
func Start(bot *tgbot.TgBot) {
|
||||
log.Info("skd start...")
|
||||
if bot == nil {
|
||||
return
|
||||
}
|
||||
ctx := context.Background()
|
||||
if statg.Conf.RunMod != consts.RunModRelease {
|
||||
return
|
||||
}
|
||||
|
||||
_, _ = botCron.AddFunc("0 5 0/1 * * ?", func() {
|
||||
log.Info("Cron Hourly Entry...")
|
||||
// 发送消息 统计数据
|
||||
curStatTime := utils.RecentMinute(time.Now(), 60) // 按60分钟对齐
|
||||
endpoints := statg.GlobalEndpoints.GetIndexEndpoints(statg.Conf.ServerIndex).GetBotStatEndpoints()
|
||||
for _, end := range endpoints {
|
||||
id := end.AppId
|
||||
tm := curStatTime
|
||||
statutils.ServerMon.RunWithName(func() error {
|
||||
return DailyBotReportTask(ctx, bot, id, tm)
|
||||
}, statutils.GetFuncName(DailyBotReportTask))
|
||||
}
|
||||
fmt.Printf("Cron Hourly %v", curStatTime)
|
||||
if statg.Conf.ServerIndex.IsMadou() {
|
||||
if curStatTime.Hour() == 8 {
|
||||
// statutils.ServerMon.Run(SkdGameTask) 麻豆不发送集团数据
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
_, _ = botCron.AddFunc("0 6 0/1 * * ?", func() {
|
||||
if statg.Conf.ServerIndex.IsMadou() {
|
||||
curStatTime := utils.RecentMinute(time.Now(), 60) // 按60分钟对齐
|
||||
statutils.ServerMon.RunWithName(func() error {
|
||||
return DailyBotRankTask(ctx, bot, curStatTime)
|
||||
}, statutils.GetFuncName(DailyBotRankTask))
|
||||
}
|
||||
})
|
||||
|
||||
_, _ = botCron.AddFunc("*/5 * * * * ?", func() {
|
||||
SaveServerKeepAliveTime()
|
||||
})
|
||||
|
||||
botCron.Start()
|
||||
}
|
||||
Reference in New Issue
Block a user