feat: support add redis queue with alarm/nbi_pm/nbi_kpi, support generate all nbi pm data
This commit is contained in:
@@ -10,6 +10,20 @@ import (
|
||||
"github.com/redis/go-redis/v9"
|
||||
)
|
||||
|
||||
const (
|
||||
// MaxMessages is the maximum number of messages to retain in each stream
|
||||
// This is set to 2000 as per the original code
|
||||
// It ensures that only the latest 2000 messages are kept in the stream
|
||||
// This helps in managing memory and performance by not allowing the stream to grow indefinitely
|
||||
// If you need to change this, make sure to update it in all relevant places
|
||||
// across the codebase to maintain consistency
|
||||
// and avoid unexpected behavior.
|
||||
// Note: This value should be consistent with the XTRIM command used in the code
|
||||
// to trim the stream.
|
||||
// If you change this value, also update the XTRIM command accordingly.
|
||||
maxMessages = 2000 // Maximum number of messages to retain in each stream
|
||||
)
|
||||
|
||||
// 写入 alarm_relation 消息
|
||||
func AddAlarmRelationQueue(ids []string) error {
|
||||
payload := map[string][]string{"ids": ids}
|
||||
@@ -27,7 +41,29 @@ func AddAlarmRelationQueue(ids []string) error {
|
||||
}).Result()
|
||||
|
||||
// 只保留最新2000条消息
|
||||
client.XTrimMaxLen(context.Background(), "alarm_relation", 2000).Result()
|
||||
client.XTrimMaxLen(context.Background(), "alarm_relation", maxMessages).Result()
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// 写入 alarm 消息
|
||||
func AddAlarmQueue(id string) error {
|
||||
payload := map[string]string{"id": id}
|
||||
payloadBytes, err := json.Marshal(payload)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
values := map[string]interface{}{
|
||||
"payload": string(payloadBytes),
|
||||
}
|
||||
|
||||
_, err = client.XAdd(ctx, &redis.XAddArgs{
|
||||
Stream: "alarm",
|
||||
Values: values,
|
||||
}).Result()
|
||||
|
||||
// 只保留最新2000条消息
|
||||
client.XTrimMaxLen(context.Background(), "alarm", maxMessages).Result()
|
||||
|
||||
return err
|
||||
}
|
||||
@@ -48,13 +84,34 @@ func AddNbiCMQueue(ids []string) error {
|
||||
}).Result()
|
||||
|
||||
// 只保留最新2000条消息
|
||||
client.XTrimMaxLen(context.Background(), "nbi_cm", 2000).Result()
|
||||
client.XTrimMaxLen(context.Background(), "nbi_cm", maxMessages).Result()
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// 写入 kpi_report_xxx 消息
|
||||
func AddNbiKpiQueue(neType, id string) error {
|
||||
payload := map[string]string{"neType": neType, "id": id}
|
||||
payloadBytes, err := json.Marshal(payload)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
values := map[string]interface{}{
|
||||
"payload": string(payloadBytes),
|
||||
}
|
||||
_, err = client.XAdd(ctx, &redis.XAddArgs{
|
||||
Stream: "nbi_kpi",
|
||||
Values: values,
|
||||
}).Result()
|
||||
|
||||
// 只保留最新2000条消息
|
||||
client.XTrimMaxLen(context.Background(), "nbi_kpi", maxMessages).Result()
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// 写入 nbi_pm 消息
|
||||
func AddNbiPMQueue(neType, id string) error {
|
||||
func AddNbiPMQueueOrg(neType, id string) error {
|
||||
payload := map[string]string{"neType": neType, "id": id}
|
||||
payloadBytes, err := json.Marshal(payload)
|
||||
if err != nil {
|
||||
@@ -69,7 +126,28 @@ func AddNbiPMQueue(neType, id string) error {
|
||||
}).Result()
|
||||
|
||||
// 只保留最新2000条消息
|
||||
client.XTrimMaxLen(context.Background(), "nbi_pm", 2000).Result()
|
||||
client.XTrimMaxLen(context.Background(), "nbi_pm", maxMessages).Result()
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// 写入 nbi_pm 消息
|
||||
func AddNbiPMQueue(id string) error {
|
||||
payload := map[string]string{"id": id}
|
||||
payloadBytes, err := json.Marshal(payload)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
values := map[string]interface{}{
|
||||
"payload": string(payloadBytes),
|
||||
}
|
||||
_, err = client.XAdd(ctx, &redis.XAddArgs{
|
||||
Stream: "nbi_pm",
|
||||
Values: values,
|
||||
}).Result()
|
||||
|
||||
// 只保留最新2000条消息
|
||||
client.XTrimMaxLen(context.Background(), "nbi_pm", maxMessages).Result()
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user