-
Notifications
You must be signed in to change notification settings - Fork 14
/
delayed_queue.go
36 lines (29 loc) · 976 Bytes
/
delayed_queue.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package delayedqueue
import (
"context"
"github.com/go-redis/redis/v8"
"github.com/xorcare/pointer"
"github.com/coretrix/hitrix/pkg/dto/delayedqueue"
"github.com/coretrix/hitrix/service"
)
func Get(ctx context.Context) *delayedqueue.List {
appService := service.DI().App()
ormService := service.DI().OrmEngineForContext(ctx)
result := &delayedqueue.List{Rows: make([]delayedqueue.Row, len(appService.RedisDelayedQueues))}
for i, queue := range appService.RedisDelayedQueues {
result.Rows[i].Queue = queue
result.Rows[i].Total = ormService.GetRedis(appService.RedisPools.Persistent).ZCount(queue, "-inf", "+inf")
values := ormService.GetRedis(appService.RedisPools.Persistent).ZRangeArgsWithScores(redis.ZRangeArgs{
Key: queue,
Start: 0,
Stop: "+inf",
Offset: 0,
Count: 1,
Rev: true,
ByScore: true})
if len(values) > 0 {
result.Rows[i].LatestItem = pointer.Uint64(uint64(values[0].Score))
}
}
return result
}