sync: 同步 v1.0.4 并脱敏配置与镜像
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"git.5iot.com/iotlcm-public/iotlcm-admin-svr/internal/dao"
|
||||
"git.5iot.com/iotlcm-public/iotlcm-admin-svr/internal/logic/warningnotify"
|
||||
"git.5iot.com/iotlcm-public/iotlcm-admin-svr/internal/model/entity"
|
||||
"git.5iot.com/iotlcm-public/iotlcm-admin-svr/internal/service"
|
||||
"strconv"
|
||||
@@ -46,16 +47,17 @@ func (s *sSimWarning) scan(ctx context.Context, scope scanScope) {
|
||||
scope = normalizeScanScope(scope)
|
||||
runTime := time.Now()
|
||||
stats := scanStats{}
|
||||
pendingWarnings := make([]pendingWarning, 0)
|
||||
collector := warningnotify.NewCollector()
|
||||
g.Log().Infof(ctx, "SimWarning.Scan begin, runTime:%s, scope:%s, mode:warn_log_only", runTime.Format("2006-01-02 15:04:05"), scope)
|
||||
|
||||
var lastID int64
|
||||
for page := 1; ; page++ {
|
||||
if err := ctx.Err(); err != nil {
|
||||
stats.ErrorCount++
|
||||
g.Log().Warningf(ctx, "SimWarning.Scan canceled, page:%d, scope:%s, err:%+v", page, scope, err)
|
||||
break
|
||||
}
|
||||
configs, err := s.queryConfigs(ctx, page, scope)
|
||||
configs, err := s.queryConfigs(ctx, lastID, scope)
|
||||
if err != nil {
|
||||
stats.ErrorCount++
|
||||
g.Log().Errorf(ctx, "SimWarning.Scan query configs failed, page:%d, err:%+v", page, err)
|
||||
@@ -64,6 +66,7 @@ func (s *sSimWarning) scan(ctx context.Context, scope scanScope) {
|
||||
if len(configs) == 0 {
|
||||
break
|
||||
}
|
||||
lastID = configs[len(configs)-1].Id
|
||||
stats.ConfigCount += len(configs)
|
||||
|
||||
cardMap, err := s.queryCards(ctx, configs)
|
||||
@@ -78,19 +81,30 @@ func (s *sSimWarning) scan(ctx context.Context, scope scanScope) {
|
||||
g.Log().Errorf(ctx, "SimWarning.Scan query flow pools failed, page:%d, err:%+v", page, err)
|
||||
break
|
||||
}
|
||||
pendingWarnings := make([]pendingWarning, 0, len(configs))
|
||||
for _, cfg := range configs {
|
||||
if pending := s.scanConfig(ctx, cfg, cardMap[itemKey(cfg.TenantId, cfg.ItemId)], poolMap[itemKey(cfg.TenantId, cfg.ItemId)], runTime, &stats); pending != nil {
|
||||
pendingWarnings = append(pendingWarnings, *pending)
|
||||
}
|
||||
}
|
||||
stored := s.storePendingWarningsWithoutNotify(ctx, pendingWarnings, runTime, &stats)
|
||||
events := make([]warningnotify.Event, 0, len(stored))
|
||||
for _, item := range stored {
|
||||
events = append(events, warningNotifyEvent(ctx, item, runTime))
|
||||
s.scanAutoAction(ctx, item.Hit, item.Record.WarnLogID, runTime, &stats)
|
||||
}
|
||||
if err := collector.Add(ctx, events); err != nil {
|
||||
stats.ErrorCount++
|
||||
g.Log().Errorf(ctx, "warning recipient aggregation failed: %+v", err)
|
||||
}
|
||||
if len(configs) < scanPageSize {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
storedWarnings := s.storePendingWarnings(ctx, pendingWarnings, runTime, &stats)
|
||||
for _, stored := range storedWarnings {
|
||||
s.scanAutoAction(ctx, stored.Hit, stored.Record.WarnLogID, runTime, &stats)
|
||||
if err := collector.Flush(ctx); err != nil {
|
||||
stats.ErrorCount++
|
||||
g.Log().Errorf(ctx, "warning notification failed: %+v", err)
|
||||
}
|
||||
|
||||
g.Log().Infof(
|
||||
@@ -107,7 +121,7 @@ func (s *sSimWarning) scan(ctx context.Context, scope scanScope) {
|
||||
)
|
||||
}
|
||||
|
||||
func (s *sSimWarning) queryConfigs(ctx context.Context, page int, scope scanScope) ([]warnConfig, error) {
|
||||
func (s *sSimWarning) queryConfigs(ctx context.Context, lastID int64, scope scanScope) ([]warnConfig, error) {
|
||||
scope = normalizeScanScope(scope)
|
||||
columns := dao.TWarnConfig.Columns()
|
||||
mod := dao.TWarnConfig.Ctx(ctx).
|
||||
@@ -162,8 +176,8 @@ func (s *sSimWarning) queryConfigs(ctx context.Context, page int, scope scanScop
|
||||
}
|
||||
|
||||
entities := make([]entity.TWarnConfig, 0)
|
||||
err := mod.OrderAsc(columns.Id).
|
||||
Page(page, scanPageSize).
|
||||
err := mod.WhereGT(columns.Id, lastID).OrderAsc(columns.Id).
|
||||
Limit(scanPageSize).
|
||||
Scan(&entities)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -279,6 +293,12 @@ func (s *sSimWarning) scanFlowPoolConfig(ctx context.Context, cfg warnConfig, po
|
||||
}
|
||||
|
||||
func (s *sSimWarning) storePendingWarnings(ctx context.Context, pendingWarnings []pendingWarning, runTime time.Time, stats *scanStats) []storedWarning {
|
||||
stored := s.storePendingWarningsWithoutNotify(ctx, pendingWarnings, runTime, stats)
|
||||
notifyStoredWarnings(ctx, stored, runTime)
|
||||
return stored
|
||||
}
|
||||
|
||||
func (s *sSimWarning) storePendingWarningsWithoutNotify(ctx context.Context, pendingWarnings []pendingWarning, runTime time.Time, stats *scanStats) []storedWarning {
|
||||
if len(pendingWarnings) == 0 {
|
||||
return nil
|
||||
}
|
||||
@@ -298,7 +318,6 @@ func (s *sSimWarning) storePendingWarnings(ctx context.Context, pendingWarnings
|
||||
for _, item := range storedWarnings {
|
||||
logWarningHit(ctx, item.Hit, item.Record)
|
||||
}
|
||||
notifyStoredWarnings(ctx, storedWarnings, runTime)
|
||||
return storedWarnings
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user