优化
This commit is contained in:
@@ -80,14 +80,32 @@ func (t *DevicePersistTask) Persist() {
|
||||
}
|
||||
}
|
||||
|
||||
// 批量删除成功处理的记录
|
||||
if len(succeeded) > 0 {
|
||||
total := len(devices)
|
||||
persisted := len(succeeded)
|
||||
failed := total - persisted
|
||||
|
||||
// 批量删除成功刷入的记录,失败的保留在 Redis 等待下次重试
|
||||
if persisted > 0 {
|
||||
if err := t.rdb.HDel(ctx, "devices", succeeded...).Err(); err != nil {
|
||||
t.log.Error("redis HDel failed", zap.Int("count", len(succeeded)), zap.Error(err))
|
||||
t.log.Error("redis HDel failed after persist",
|
||||
zap.Int("persisted", persisted),
|
||||
zap.Error(err),
|
||||
)
|
||||
} else {
|
||||
t.log.Info("devices persisted and removed from redis", zap.Int("count", len(succeeded)))
|
||||
t.log.Info("devices persisted to database and removed from redis",
|
||||
zap.Int("persisted", persisted),
|
||||
zap.Int("total", total),
|
||||
zap.Int("failed", failed),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
if failed > 0 {
|
||||
t.log.Warn("some devices failed to persist, kept in redis for retry",
|
||||
zap.Int("failed", failed),
|
||||
zap.Int("total", total),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// persistDevice 处理 user_device 表写入
|
||||
|
||||
Reference in New Issue
Block a user