Files
junhong_cmp_fiber/migrations/000252_add_polling_check_scene.up.sql
邹进 dae44bed30 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 估算)、抢执行权、续期、收尾、请求检查(合并、冷却、执行中打优先标记)、移出、发布失败释放
2026-10-25 18:28:42 +09:00

42 lines
3.0 KiB
SQL
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
-- 业务事件与读入口检查场景(add-carrier-polling-scheduler)。
-- 背景:业务事件与读入口原先各自起"立即、3 分钟、5 分钟"卡观测序列,不受限流、与优先轮询重复;
-- 改为"请求检查":把卡的对应检查类型设为立即到期放入运营商账户优先队列,按场景配置确认延迟与冷却。
--
-- 设计选择:
-- 1. scene 唯一,场景由代码预置;后台只可修改检查类型、确认延迟与冷却时长。
-- 2. check_types 取值 card_status / carddata / realname;confirm_delays 为秒数数组(空数组表示只立即检查一次);
-- cooldown 为秒数,空表示不冷却(读入口场景默认配置冷却,避免反复刷新占满优先队列)。
-- 3. 停复机成功与设备操作默认 3 分钟后确认一次(结果已满足预期时取消),沿用原观测序列的确认语义。
CREATE TABLE tb_polling_check_scene (
id BIGSERIAL PRIMARY KEY,
scene VARCHAR(50) NOT NULL,
scene_name VARCHAR(100) NOT NULL,
check_types JSONB NOT NULL DEFAULT '[]'::jsonb,
confirm_delays JSONB NOT NULL DEFAULT '[]'::jsonb,
cooldown INTEGER,
updater BIGINT NOT NULL DEFAULT 0,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
CONSTRAINT ck_polling_check_scene_cooldown CHECK (cooldown IS NULL OR cooldown > 0)
);
CREATE UNIQUE INDEX uk_polling_check_scene_scene ON tb_polling_check_scene (scene);
COMMENT ON TABLE tb_polling_check_scene IS '业务事件与读入口请求检查场景';
COMMENT ON COLUMN tb_polling_check_scene.scene IS '场景编码(代码预置)';
COMMENT ON COLUMN tb_polling_check_scene.scene_name IS '场景名称';
COMMENT ON COLUMN tb_polling_check_scene.check_types IS '需要检查的类型:card_status / carddata / realname';
COMMENT ON COLUMN tb_polling_check_scene.confirm_delays IS '延迟确认序列(秒),空数组表示只立即检查一次';
COMMENT ON COLUMN tb_polling_check_scene.cooldown IS '冷却时长(秒):最近一次成功检查未超过该时长则不请求,空表示不冷却';
INSERT INTO tb_polling_check_scene (scene, scene_name, check_types, confirm_delays, cooldown) VALUES
('order_paid', '订单支付', '["card_status","carddata","realname"]', '[]', NULL),
('package_activated', '套餐激活', '["card_status","carddata","realname"]', '[]', NULL),
('stop_resume_succeeded', '停复机成功', '["card_status"]', '[180]', NULL),
('device_operation', '设备操作', '["card_status"]', '[180]', NULL),
('auto_renewal_purchase', '自动续费购包', '["card_status","carddata","realname"]', '[]', NULL),
('client_asset_detail', 'C 端资产详情', '["card_status","carddata"]', '[]', 300),
('admin_asset_realtime', '后台资产实时状态', '["card_status","carddata","realname"]', '[]', 60),
('realname_link', '实名链接', '["realname"]', '[]', 60);