43 lines
1.3 KiB
Go
43 lines
1.3 KiB
Go
package rabbitmq
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/gogf/gf/v2/frame/g"
|
|
|
|
"git.5iot.com/iotlcm-public/iotlcm-worker-svr/internal/consts"
|
|
mq "git.5iot.com/iotlcm-public/iotlcm-worker-svr/internal/library/rabbitmq"
|
|
"git.5iot.com/iotlcm-public/iotlcm-worker-svr/internal/model"
|
|
)
|
|
|
|
func (c *Consumers) initTrafficUsageDailyRetry(ctx context.Context) error {
|
|
if !mq.Enabled(ctx) {
|
|
g.Log().Info(ctx, "traffic usage daily retry consumer skipped, RabbitMQ disabled")
|
|
return nil
|
|
}
|
|
if err := mq.ConsumeJSON[model.TrafficUsageDailyRetryMessage](
|
|
ctx,
|
|
consts.QueueTrafficUsageDailyRetry,
|
|
"iotlcm-traffic-usage-daily",
|
|
c.handleTrafficUsageDailyRetry,
|
|
); err != nil {
|
|
return err
|
|
}
|
|
g.Log().Infof(ctx, "traffic usage daily retry consumer started, queue:%s", consts.QueueTrafficUsageDailyRetry)
|
|
return nil
|
|
}
|
|
|
|
func (c *Consumers) handleTrafficUsageDailyRetry(ctx context.Context, message model.TrafficUsageDailyRetryMessage) error {
|
|
err := validateTrafficUsageIdentity(message.SimKey, message.Card)
|
|
if err == nil {
|
|
err = c.trafficUsage.RetryDaily(ctx, message)
|
|
}
|
|
if err == nil {
|
|
return nil
|
|
}
|
|
message.Attempt++
|
|
message.LastError = err.Error()
|
|
permanent := trafficUsageFailureSnapshot(err, &message.UsageMb)
|
|
return publishTrafficUsageFailure(ctx, consts.QueueTrafficUsageDailyRetry, message, message.Attempt, permanent)
|
|
}
|