otto 9 months ago
parent
commit
6726d9bca7
  1. 2
      hotspot-clear-job-dev.yaml
  2. 54
      task/task.go

2
hotspot-clear-job-dev.yaml

@ -12,7 +12,7 @@ spec:
spec:
containers:
- name: hotspot-clear
image: 192.168.1.131:8888/job/dev/hotspot-clear:79b62d1f2cbcbfee17586c8ae7c24a76a34e97fd
image: 192.168.1.131:8888/job/dev/hotspot-clear:2dfb5805e047bbfab6eee03073fc963204927cde
env:
- name: JM_ENVIRONMENT
value: dev

54
task/task.go

@ -51,7 +51,7 @@ func NewTask() {
func task(start, end int64) error {
redisClient := NewRedis()
result, err := redisClient.ZRange(context.Background(), hotKey, start, end).Result()
result, err := redisClient.ZRangeWithScores(context.Background(), hotKey, start, end).Result()
if err != nil {
return err
}
@ -62,32 +62,36 @@ func task(start, end int64) error {
members []redis.Z
ids []int64
)
for _, id := range result {
i, _ := strconv.Atoi(id)
if i != 0 {
ids = append(ids, int64(i))
}
members = append(members, redis.Z{
Member: id,
Score: 0,
})
}
err = redisClient.ZAdd(context.Background(), hotKey, members...).Err()
if err != nil {
return err
}
for _, val := range result {
roomClient, roomClientClose, err := client.GetRoomClientV2(context.Background())
if err != nil {
return err
if val.Score > 0 {
id, _ := strconv.Atoi(val.Member.(string))
if id != 0 {
ids = append(ids, int64(id))
members = append(members, redis.Z{
Member: id,
Score: 0,
})
}
}
}
defer roomClientClose()
_, err = roomClient.IncrRoomHotspot(context.Background(), &v2.IncrRoomHotspotReq{
RoomIdList: ids,
HotValue: 0,
})
if err != nil {
return err
if len(ids) != 0 {
err = redisClient.ZAdd(context.Background(), hotKey, members...).Err()
if err != nil {
return err
}
roomClient, roomClientClose, err := client.GetRoomClientV2(context.Background())
if err != nil {
return err
}
defer func() { _ = roomClientClose() }()
_, err = roomClient.IncrRoomHotspot(context.Background(), &v2.IncrRoomHotspotReq{
RoomIdList: ids,
HotValue: 0,
})
if err != nil {
return err
}
}
// 递增查询
start = end + 1

Loading…
Cancel
Save