|
|
|
@ -80,95 +80,51 @@ func InitRankJob(svcCtx *svc.ServiceContext) {
|
|
|
|
|
// 3. 开启任务 定时落库
|
|
|
|
|
func (j *Job) initJob() {
|
|
|
|
|
logx.Info("开启排行榜服务...")
|
|
|
|
|
j.initByType(model.RankTypeDamage)
|
|
|
|
|
j.initByType(model.RankTypeDeDamage)
|
|
|
|
|
j.initByType(model.RankTypeGeneral)
|
|
|
|
|
j.initByType(model.RankTypeDeGeneral)
|
|
|
|
|
j.initByType(model.RankTypeKillUnit)
|
|
|
|
|
j.initByType(model.RankTypeDeKillUnit)
|
|
|
|
|
j.initByType(model.RankTypeKillPlayer)
|
|
|
|
|
j.initByType(model.RankTypeDeKillPlayer)
|
|
|
|
|
j.initByType(model.RankTypeWin)
|
|
|
|
|
j.initByType(model.RankTypeLost)
|
|
|
|
|
j.initByType(model.RankTypeFirstBlood)
|
|
|
|
|
j.initByType(model.RankTypeDeFirstBlood)
|
|
|
|
|
// TODO 读取历史数据功能暂时移除
|
|
|
|
|
//j.initByType(model.RankTypeDamage)
|
|
|
|
|
//j.initByType(model.RankTypeDeDamage)
|
|
|
|
|
//j.initByType(model.RankTypeGeneral)
|
|
|
|
|
//j.initByType(model.RankTypeDeGeneral)
|
|
|
|
|
//j.initByType(model.RankTypeKillUnit)
|
|
|
|
|
//j.initByType(model.RankTypeDeKillUnit)
|
|
|
|
|
//j.initByType(model.RankTypeKillPlayer)
|
|
|
|
|
//j.initByType(model.RankTypeDeKillPlayer)
|
|
|
|
|
//j.initByType(model.RankTypeWin)
|
|
|
|
|
//j.initByType(model.RankTypeLost)
|
|
|
|
|
//j.initByType(model.RankTypeFirstBlood)
|
|
|
|
|
//j.initByType(model.RankTypeDeFirstBlood)
|
|
|
|
|
|
|
|
|
|
cfg := j.svcCtx.Config.Rank
|
|
|
|
|
// job read and update
|
|
|
|
|
c := cron.New()
|
|
|
|
|
_, _ = c.AddFunc(cfg.Cron.Update, func() {
|
|
|
|
|
j.readAndUpdate(model.RankTypeDamage)
|
|
|
|
|
go j.readAndUpdate(model.RankTypeDamage)
|
|
|
|
|
go j.readAndUpdate(model.RankTypeDeDamage)
|
|
|
|
|
go j.readAndUpdate(model.RankTypeGeneral)
|
|
|
|
|
go j.readAndUpdate(model.RankTypeDeGeneral)
|
|
|
|
|
go j.readAndUpdate(model.RankTypeKillUnit)
|
|
|
|
|
go j.readAndUpdate(model.RankTypeDeKillUnit)
|
|
|
|
|
go j.readAndUpdate(model.RankTypeKillPlayer)
|
|
|
|
|
go j.readAndUpdate(model.RankTypeDeKillPlayer)
|
|
|
|
|
go j.readAndUpdate(model.RankTypeWin)
|
|
|
|
|
go j.readAndUpdate(model.RankTypeLost)
|
|
|
|
|
go j.readAndUpdate(model.RankTypeFirstBlood)
|
|
|
|
|
go j.readAndUpdate(model.RankTypeDeFirstBlood)
|
|
|
|
|
})
|
|
|
|
|
_, _ = c.AddFunc(cfg.Cron.Update, func() {
|
|
|
|
|
j.readAndUpdate(model.RankTypeDeDamage)
|
|
|
|
|
})
|
|
|
|
|
_, _ = c.AddFunc(cfg.Cron.Update, func() {
|
|
|
|
|
j.readAndUpdate(model.RankTypeGeneral)
|
|
|
|
|
})
|
|
|
|
|
_, _ = c.AddFunc(cfg.Cron.Update, func() {
|
|
|
|
|
j.readAndUpdate(model.RankTypeDeGeneral)
|
|
|
|
|
})
|
|
|
|
|
_, _ = c.AddFunc(cfg.Cron.Update, func() {
|
|
|
|
|
j.readAndUpdate(model.RankTypeKillUnit)
|
|
|
|
|
})
|
|
|
|
|
_, _ = c.AddFunc(cfg.Cron.Update, func() {
|
|
|
|
|
j.readAndUpdate(model.RankTypeDeKillUnit)
|
|
|
|
|
})
|
|
|
|
|
_, _ = c.AddFunc(cfg.Cron.Update, func() {
|
|
|
|
|
j.readAndUpdate(model.RankTypeKillPlayer)
|
|
|
|
|
})
|
|
|
|
|
_, _ = c.AddFunc(cfg.Cron.Update, func() {
|
|
|
|
|
j.readAndUpdate(model.RankTypeDeKillPlayer)
|
|
|
|
|
})
|
|
|
|
|
_, _ = c.AddFunc(cfg.Cron.Update, func() {
|
|
|
|
|
j.readAndUpdate(model.RankTypeWin)
|
|
|
|
|
})
|
|
|
|
|
_, _ = c.AddFunc(cfg.Cron.Update, func() {
|
|
|
|
|
j.readAndUpdate(model.RankTypeLost)
|
|
|
|
|
})
|
|
|
|
|
_, _ = c.AddFunc(cfg.Cron.Update, func() {
|
|
|
|
|
j.readAndUpdate(model.RankTypeFirstBlood)
|
|
|
|
|
})
|
|
|
|
|
_, _ = c.AddFunc(cfg.Cron.Update, func() {
|
|
|
|
|
j.readAndUpdate(model.RankTypeDeFirstBlood)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// persistence
|
|
|
|
|
_, _ = c.AddFunc(cfg.Cron.Persistence, func() {
|
|
|
|
|
j.persistence(model.RankTypeDamage)
|
|
|
|
|
})
|
|
|
|
|
_, _ = c.AddFunc(cfg.Cron.Persistence, func() {
|
|
|
|
|
j.persistence(model.RankTypeDeDamage)
|
|
|
|
|
})
|
|
|
|
|
_, _ = c.AddFunc(cfg.Cron.Persistence, func() {
|
|
|
|
|
j.persistence(model.RankTypeGeneral)
|
|
|
|
|
})
|
|
|
|
|
_, _ = c.AddFunc(cfg.Cron.Persistence, func() {
|
|
|
|
|
j.persistence(model.RankTypeDeGeneral)
|
|
|
|
|
})
|
|
|
|
|
_, _ = c.AddFunc(cfg.Cron.Persistence, func() {
|
|
|
|
|
j.persistence(model.RankTypeKillUnit)
|
|
|
|
|
})
|
|
|
|
|
_, _ = c.AddFunc(cfg.Cron.Persistence, func() {
|
|
|
|
|
j.persistence(model.RankTypeDeKillUnit)
|
|
|
|
|
})
|
|
|
|
|
_, _ = c.AddFunc(cfg.Cron.Persistence, func() {
|
|
|
|
|
j.persistence(model.RankTypeKillPlayer)
|
|
|
|
|
})
|
|
|
|
|
_, _ = c.AddFunc(cfg.Cron.Persistence, func() {
|
|
|
|
|
j.persistence(model.RankTypeDeKillPlayer)
|
|
|
|
|
})
|
|
|
|
|
_, _ = c.AddFunc(cfg.Cron.Persistence, func() {
|
|
|
|
|
j.persistence(model.RankTypeWin)
|
|
|
|
|
})
|
|
|
|
|
_, _ = c.AddFunc(cfg.Cron.Persistence, func() {
|
|
|
|
|
j.persistence(model.RankTypeLost)
|
|
|
|
|
})
|
|
|
|
|
_, _ = c.AddFunc(cfg.Cron.Persistence, func() {
|
|
|
|
|
j.persistence(model.RankTypeFirstBlood)
|
|
|
|
|
})
|
|
|
|
|
_, _ = c.AddFunc(cfg.Cron.Persistence, func() {
|
|
|
|
|
j.persistence(model.RankTypeDeFirstBlood)
|
|
|
|
|
go j.persistence(model.RankTypeDamage)
|
|
|
|
|
go j.persistence(model.RankTypeDeDamage)
|
|
|
|
|
go j.persistence(model.RankTypeGeneral)
|
|
|
|
|
go j.persistence(model.RankTypeDeGeneral)
|
|
|
|
|
go j.persistence(model.RankTypeKillUnit)
|
|
|
|
|
go j.persistence(model.RankTypeDeKillUnit)
|
|
|
|
|
go j.persistence(model.RankTypeKillPlayer)
|
|
|
|
|
go j.persistence(model.RankTypeDeKillPlayer)
|
|
|
|
|
go j.persistence(model.RankTypeWin)
|
|
|
|
|
go j.persistence(model.RankTypeLost)
|
|
|
|
|
go j.persistence(model.RankTypeFirstBlood)
|
|
|
|
|
go j.persistence(model.RankTypeDeFirstBlood)
|
|
|
|
|
})
|
|
|
|
|
c.Start()
|
|
|
|
|
}
|
|
|
|
@ -251,16 +207,14 @@ func (j *Job) readAndUpdate(rankType int32) {
|
|
|
|
|
|
|
|
|
|
rankLen := len(rank)
|
|
|
|
|
var score int64
|
|
|
|
|
if rankLen == 0 {
|
|
|
|
|
score = 0
|
|
|
|
|
} else {
|
|
|
|
|
if rankLen > 0 {
|
|
|
|
|
// 取当前榜最后一名分数
|
|
|
|
|
score = rank[rankLen-1][1]
|
|
|
|
|
}
|
|
|
|
|
// 若榜内数量不够,则直接取 max - len 数量的人 score排序一下
|
|
|
|
|
limit := model.MaxRankN
|
|
|
|
|
if rankLen < model.MaxRankN {
|
|
|
|
|
limit = model.MaxRankN - rankLen + 1 // +1是避免取到自己后少取一位
|
|
|
|
|
limit = model.MaxRankN - rankLen + 1 // +1是避免取到自己 少取一位
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 末位 score
|
|
|
|
|