2bec257289
iotlcm-worker-svr:异步执行中枢(RabbitMQ 消费者 + 全量同步编排)。 - Go module:iotlcm-worker-svr → git.5iot.com/iotlcm-public/iotlcm-worker-svr(214 文件) - 凭据与内部标识脱敏:MySQL/Redis 凭据、私网与生产 IP、内网域名、 库名 xiujie_admin → iotlcm、哨兵名占位 - 159 处真实手机号 → 合法 11 位编造号(保留号段与后 4 位,维持互异, 不破坏「校验 MSISDN 格式」等测试断言) - 移除内部资产:CI 触发器、Jenkins 触发测试文档、预演门禁与镜像 digest 记录 - Dockerfile 改用公共基础镜像(golang:1.25-alpine → alpine:3.23), 移除写死的 git 凭据 - README 重写(架构/全量同步模型/配置/已知失败),补 Apache-2.0 LICENSE,LF 行尾 + .gitattributes 已知:3 个测试包在源仓同一提交上同样失败(client/upstream、 service/allocate、service/inbound),属既有缺陷,本仓未引入亦未修复。
82 lines
3.1 KiB
Go
82 lines
3.1 KiB
Go
package dailyusage
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/gogf/gf/v2/errors/gerror"
|
|
|
|
"git.5iot.com/iotlcm-public/iotlcm-worker-svr/internal/dao"
|
|
"git.5iot.com/iotlcm-public/iotlcm-worker-svr/internal/model/entity"
|
|
)
|
|
|
|
// channelScanner augments, rather than replaces, the legacy scanner contract.
|
|
// ListChannels is called once before any workers start. ScanChannel must not
|
|
// mutate the legacy DatabaseScanner.channelMetadata cache.
|
|
type channelScanner interface {
|
|
ListChannels(context.Context) ([]channelMetadata, error)
|
|
ScanChannel(context.Context, string, int64, int) ([]Card, error)
|
|
}
|
|
|
|
// This exact MySQL query shape is a release gate. Do not silently remove hints,
|
|
// add an SQL upper bound, or move eligibility filtering after LIMIT.
|
|
const channelPageSQL = `SELECT c.id, c.iccid, c.msisdn, c.imsi, c.chan_key, c.current_package_code
|
|
FROM t_sim_card_info AS c FORCE INDEX (idx_card_chan_key)
|
|
STRAIGHT_JOIN sys_dept AS d
|
|
ON c.dept_id = d.dept_id
|
|
AND c.tenant_id = d.tenant_id
|
|
WHERE c.chan_key = ?
|
|
AND c.id > ?
|
|
AND c.iccid <> ''
|
|
AND c.current_package_code <> ''
|
|
AND d.deleted_at IS NULL
|
|
ORDER BY c.id ASC
|
|
LIMIT ?`
|
|
|
|
func (s *DatabaseScanner) ListChannels(ctx context.Context) ([]channelMetadata, error) {
|
|
var metadata []channelMetadata
|
|
if err := dao.TSimCardInfo.DB().Model("t_sim_channels").Ctx(ctx).Fields("chan_key,temp_key,sync_enabled,operator").Scan(&metadata); err != nil {
|
|
return nil, gerror.Wrap(err, "list channel metadata")
|
|
}
|
|
return metadata, nil
|
|
}
|
|
|
|
func (s *DatabaseScanner) ScanChannel(ctx context.Context, chanKey string, lastID int64, pageSize int) ([]Card, error) {
|
|
if chanKey == "" || lastID < 0 || pageSize <= 0 {
|
|
return nil, gerror.New("invalid channel pagination parameters")
|
|
}
|
|
var rows []entity.TSimCardInfo
|
|
// Use the card DAO's database group, not a separately configured connection.
|
|
if err := dao.TSimCardInfo.DB().Raw(channelPageSQL, chanKey, lastID, pageSize).Ctx(ctx).Scan(&rows); err != nil {
|
|
return nil, gerror.Wrap(err, "scan channel cards")
|
|
}
|
|
cards := make([]Card, 0, len(rows))
|
|
for _, row := range rows {
|
|
cards = append(cards, Card{ID: row.Id, ICCID: row.Iccid, MSISDN: row.Msisdn, IMSI: row.Imsi, ChanKey: row.ChanKey, PackageCode: row.CurrentPackageCode})
|
|
}
|
|
return cards, nil
|
|
}
|
|
|
|
// Pool counters are shared with other worker traffic. Their deltas are direct
|
|
// observations, not an attribution of all connection waits to this producer.
|
|
func (*DatabaseScanner) poolWait(ctx context.Context) (int64, int64) {
|
|
var count, nanos int64
|
|
for _, item := range dao.TSimCardInfo.DB().Stats(ctx) {
|
|
stats := item.Stats()
|
|
count += stats.WaitCount
|
|
nanos += int64(stats.WaitDuration)
|
|
}
|
|
return count, nanos
|
|
}
|
|
|
|
// ValidateScanSettings is strict for values read from configuration. The Go
|
|
// constructor first fills omitted zero values; explicit YAML zero is rejected.
|
|
func ValidateScanSettings(mode string, concurrency int) error {
|
|
if mode != "serial" && mode != "channel" {
|
|
return gerror.Newf("invalid trafficUsageDailySync.producer.scanMode %q (serial or channel required)", mode)
|
|
}
|
|
if concurrency <= 0 {
|
|
return gerror.New("trafficUsageDailySync.producer.scanConcurrency must be positive")
|
|
}
|
|
return nil
|
|
}
|