feat: 按运营商账户调度的迁移、配置与账户队列 Lua
- 迁移 000251~000254:运营商账户调度参数、请求检查场景(预置 8 个)、卡轮询失败告警表,以及调度模式、步骤、退避、告警等受控系统配置(默认 legacy,行为不变);并发配置表注释标记废弃 - 受控系统配置注册与 JSON 结构校验:步骤只能是 4 种检查类型且不重复、退避序列递增 - yaml 增加 NSQ 地址、msg_timeout、租约、续期间隔、分发间隔、默认执行上限与 max_in_flight;引入 go-nsq - 测试环境 docker-compose 增加 nsqlookupd 与 nsqd,Worker 注入 NSQ 地址 - 账户队列 Redis 结构与 Lua:领取(执行上限、优先占比、按限流组剩余 QPS 估算)、抢执行权、续期、收尾、请求检查(合并、冷却、执行中打优先标记)、移出、发布失败释放
This commit is contained in:
@@ -213,6 +213,37 @@ type PollingConfig struct {
|
||||
// VerboseLog 开启后,所有轮询 handler 在成功获取上游数据时以 Info 级别输出详细日志
|
||||
// 环境变量:JUNHONG_POLLING_VERBOSE_LOG
|
||||
VerboseLog bool `mapstructure:"verbose_log"`
|
||||
// Carrier 按运营商账户调度(add-carrier-polling-scheduler)的部署参数;调度模式本身放受控系统配置 polling.scheduler.mode。
|
||||
Carrier CarrierSchedulerConfig `mapstructure:"carrier"`
|
||||
}
|
||||
|
||||
// CarrierSchedulerConfig 按运营商账户调度的 yaml 参数。
|
||||
// 约束:msg_timeout > renew_interval;lease > msg_timeout × max_attempts;执行权 TTL = renew_interval × 2。
|
||||
type CarrierSchedulerConfig struct {
|
||||
// NSQDAddress 分发器发布消息的 nsqd TCP 地址,如 nsqd:4150;为空时新调度不可用(切到 carrier 会告警并保持不领取)。
|
||||
// 环境变量:JUNHONG_POLLING_CARRIER_NSQD_ADDRESS
|
||||
NSQDAddress string `mapstructure:"nsqd_address"`
|
||||
// NSQLookupdAddresses 消费者发现 nsqd 的 nsqlookupd HTTP 地址,逗号分隔,如 nsqlookupd:4161;为空时消费者直连 NSQDAddress。
|
||||
// 环境变量:JUNHONG_POLLING_CARRIER_NSQLOOKUPD_ADDRESSES
|
||||
NSQLookupdAddresses string `mapstructure:"nsqlookupd_addresses"`
|
||||
// MsgTimeout NSQ 消息超时,须大于续期间隔,执行中靠 Touch 延长。
|
||||
MsgTimeout time.Duration `mapstructure:"msg_timeout"`
|
||||
// MaxAttempts NSQ 允许的投递次数(含首次)。
|
||||
MaxAttempts uint16 `mapstructure:"max_attempts"`
|
||||
// Lease 处理中标记 TTL(租约),须大于 msg_timeout × max_attempts。
|
||||
Lease time.Duration `mapstructure:"lease"`
|
||||
// RenewInterval 租约续期间隔,默认租约 / 3 以内。
|
||||
RenewInterval time.Duration `mapstructure:"renew_interval"`
|
||||
// DispatchInterval 分发间隔。
|
||||
DispatchInterval time.Duration `mapstructure:"dispatch_interval"`
|
||||
// ShutdownGrace 优雅退出宽限期:停止分发与订阅后等待执行中任务完成的时长。
|
||||
ShutdownGrace time.Duration `mapstructure:"shutdown_grace"`
|
||||
// DefaultInflightLimit 未配置调度参数的账户同时执行卡任务的上限(跨实例)。
|
||||
DefaultInflightLimit int `mapstructure:"default_inflight_limit"`
|
||||
// DefaultCardMaxInFlight 未配置调度参数的账户每进程消费卡任务的 max_in_flight。
|
||||
DefaultCardMaxInFlight int `mapstructure:"default_card_max_in_flight"`
|
||||
// SubscriberProcesses 订阅卡任务 topic 的 Worker 进程数,用于校验执行上限不超过各进程 max_in_flight 之和。
|
||||
SubscriberProcesses int `mapstructure:"subscriber_processes"`
|
||||
}
|
||||
|
||||
// PollingAutoTriggerConfig 轮询自动触发配置
|
||||
|
||||
@@ -133,6 +133,19 @@ gateway:
|
||||
# 轮询配置
|
||||
polling:
|
||||
verbose_log: false # 是否开启详细日志(环境变量:JUNHONG_POLLING_VERBOSE_LOG)
|
||||
# 按运营商账户调度(调度模式在受控系统配置 polling.scheduler.mode 切换)
|
||||
carrier:
|
||||
nsqd_address: "" # nsqd TCP 地址,如 nsqd:4150(环境变量:JUNHONG_POLLING_CARRIER_NSQD_ADDRESS)
|
||||
nsqlookupd_addresses: "" # nsqlookupd HTTP 地址,逗号分隔(环境变量:JUNHONG_POLLING_CARRIER_NSQLOOKUPD_ADDRESSES)
|
||||
msg_timeout: 90s # NSQ 消息超时,须大于续期间隔
|
||||
max_attempts: 3 # NSQ 允许投递次数(含首次)
|
||||
lease: 300s # 处理中标记 TTL,须大于 msg_timeout × max_attempts
|
||||
renew_interval: 30s # 租约续期间隔
|
||||
dispatch_interval: 1s # 分发间隔
|
||||
shutdown_grace: 30s # 优雅退出宽限期
|
||||
default_inflight_limit: 20 # 未配置账户的执行上限(跨实例)
|
||||
default_card_max_in_flight: 20 # 未配置账户的每进程 max_in_flight
|
||||
subscriber_processes: 1 # 订阅卡任务的 Worker 进程数(校验执行上限用)
|
||||
|
||||
# 轮询自动触发配置
|
||||
polling_auto_trigger:
|
||||
|
||||
@@ -131,6 +131,9 @@ func bindEnvVariables(v *viper.Viper) {
|
||||
"gateway.app_secret",
|
||||
"gateway.timeout",
|
||||
"polling.verbose_log",
|
||||
"polling.carrier.nsqd_address",
|
||||
"polling.carrier.nsqlookupd_addresses",
|
||||
"polling.carrier.subscriber_processes",
|
||||
"polling_auto_trigger.enable_auto_trigger",
|
||||
"polling_auto_trigger.auto_trigger_system_user_id",
|
||||
"worker.role",
|
||||
|
||||
Reference in New Issue
Block a user