2026-06-23 11:53:00 +08:00

29 lines
1.1 KiB
Go

package app
import "context"
func (a *App) runBackgroundWorkers() {
if a.walletSvc == nil {
return
}
ctx, cancel := context.WithCancel(context.Background())
a.stopWorker = cancel
if a.outboxWorkerCfg.Enabled && a.outboxProducer != nil {
excludedRealtimeTypes := []string(nil)
if a.realtimeOutboxWorkerCfg.Enabled && a.realtimeOutboxProducer != nil {
// 普通账务 worker 在实时通道可用时跳过红包 UI 事件,避免两个 worker 抢同一行。
excludedRealtimeTypes = a.realtimeOutboxWorkerCfg.EventTypes
}
a.startWalletOutboxWorkers(ctx, "wallet-outbox", a.outboxWorkerCfg, a.outboxProducer, a.walletOutboxTopic, nil, excludedRealtimeTypes)
}
if a.realtimeOutboxWorkerCfg.Enabled && a.realtimeOutboxProducer != nil {
a.startWalletOutboxWorkers(ctx, "wallet-realtime-outbox", a.realtimeOutboxWorkerCfg, a.realtimeOutboxProducer, a.realtimeWalletOutboxTopic, a.realtimeOutboxWorkerCfg.EventTypes, nil)
}
if a.externalRechargeReconcileWorkerCfg.Enabled {
a.startExternalRechargeReconcileWorker(ctx)
}
if a.redPacketExpiryWorkerCfg.Enabled {
a.startRedPacketExpiryWorker(ctx)
}
}