package rank import ( "math/rand" "mongo.games.com/game/common" "mongo.games.com/game/model" "mongo.games.com/game/ranksrv/com" "mongo.games.com/goserver/core/basic" "mongo.games.com/goserver/core/logger" "mongo.games.com/goserver/core/task" "time" ) var InviteLogMgrInstance = com.NewListMgr[*model.InviteInfo]( func() int64 { return 5 // 缓存5秒 }, func(platform string, index int32) ([]*model.InviteInfo, error) { logger.Logger.Tracef("load invitelog platform:%s snid:%d", platform, index) ret, err := model.GetInviteList(platform, index) if err != nil { logger.Logger.Errorf("load invitelog err:%s", err.Error()) return nil, err } return ret, nil }) var RobotInviteMgr = &RobotManager{} type RobotManager struct { } func (this *RobotManager) InterestClockEvent() int { return 1 << common.ClockEventDay } func (this *RobotManager) OnMonthTimer() { } func (this *RobotManager) ClockEventMax() { return } func (this *RobotManager) OnSecTimer() { } func (this *RobotManager) OnMiniTimer() { } func (this *RobotManager) OnHourTimer() { } func (this *RobotManager) OnWeekTimer() { } func (this *RobotManager) OnShutdown() { } func (this *RobotManager) OnDayTimer() { RobotRandon() } func RobotRandon() { //机器人随机 robotNum := rand.Intn(21) + 10 accounts := model.GetRobotAccounts(200) task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} { for i := 0; i < robotNum; i++ { //随机机器人 snId := accounts[rand.Intn(len(accounts))].SnId num := int64(rand.Intn(8) + 1) score := num*50 + int64(rand.Intn(551)+50) data := model.RankInvite{ Platform: "1", SnId: snId, Num: num, Score: score, Ts: time.Now().Unix(), Week: common.GetWeekStartTs(time.Now().Unix()), } err := model.SaveRankInvite(&data) if err != nil { logger.Logger.Error("SaveRankInviteTask error %v", err) return err } } return nil }), task.CompleteNotifyWrapper(func(data interface{}, tt task.Task) { InviteLogMgrInstance.UpdateCache("1", 2) })).StartByFixExecutor("SaveRankInviteTask") } func init() { common.ClockMgrSingleton.RegisterSinker(RobotInviteMgr) }