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),属既有缺陷,本仓未引入亦未修复。
91 lines
2.3 KiB
Go
91 lines
2.3 KiB
Go
package monthlyusage
|
|
|
|
import (
|
|
"context"
|
|
"git.5iot.com/iotlcm-public/iotlcm-worker-svr/internal/fullsync/supply"
|
|
"github.com/gogf/gf/v2/frame/g"
|
|
"time"
|
|
)
|
|
|
|
func (p *Producer) observe(key, stage string, pending int, added, ended bool) {
|
|
if p.observation != nil {
|
|
p.observation.Event(key, stage, pending, added, ended, time.Now())
|
|
}
|
|
}
|
|
func (p *Producer) startObservation(ctx context.Context, run string, keys []string, started time.Time) func(bool) {
|
|
tracker := p.config.SupplyObservation
|
|
if tracker == nil {
|
|
return func(bool) {}
|
|
}
|
|
o := supply.New(newOwner(), started, keys)
|
|
p.observation = o
|
|
readCtx, readCancel := context.WithTimeout(context.Background(), 500*time.Millisecond)
|
|
meta, err := p.store.GetRunMeta(readCtx, run)
|
|
readCancel()
|
|
if err != nil {
|
|
o.Partial()
|
|
} else if meta.SupplyObservation != nil {
|
|
o.Restore(*meta.SupplyObservation)
|
|
}
|
|
tracker.Put(run, o)
|
|
stop := make(chan struct{})
|
|
done := make(chan struct{})
|
|
flush := func() {
|
|
writeCtx, cancel := context.WithTimeout(context.Background(), 500*time.Millisecond)
|
|
defer cancel()
|
|
encoded, e := o.Encode()
|
|
if e == nil {
|
|
var saved bool
|
|
saved, e = p.store.SaveSupply(writeCtx, run, p.config.RunLockKey, p.owner, encoded)
|
|
if !saved && e == nil {
|
|
o.Partial()
|
|
}
|
|
}
|
|
if e != nil {
|
|
o.Partial()
|
|
g.Log().Warningf(writeCtx, "event=supply_observation status=partial runId=%s error=%q", run, e.Error())
|
|
}
|
|
}
|
|
go func() {
|
|
defer close(done)
|
|
sampleTicker := time.NewTicker(time.Second)
|
|
defer sampleTicker.Stop()
|
|
flushTicker := time.NewTicker(10 * time.Second)
|
|
defer flushTicker.Stop()
|
|
for {
|
|
select {
|
|
case <-stop:
|
|
return
|
|
case <-ctx.Done():
|
|
o.Partial()
|
|
return
|
|
case <-flushTicker.C:
|
|
flush()
|
|
case <-sampleTicker.C:
|
|
views := o.Views()
|
|
sampleCtx, cancel := context.WithTimeout(context.Background(), 500*time.Millisecond)
|
|
samples, e := p.store.ReadSupply(sampleCtx, run, keys, time.Now())
|
|
cancel()
|
|
now := time.Now()
|
|
for _, key := range keys {
|
|
s := samples[key]
|
|
if e != nil || !tracker.LocalConsumer || !tracker.ConsumerActive.Load() {
|
|
s.Known = false
|
|
}
|
|
o.Apply(key, views[key], s, now)
|
|
}
|
|
}
|
|
}
|
|
}()
|
|
return func(success bool) {
|
|
close(stop)
|
|
<-done
|
|
if !success {
|
|
o.Partial()
|
|
}
|
|
flush()
|
|
tracker.Remove(run)
|
|
p.observation = nil
|
|
}
|
|
}
|