fix: 修正轮询配置多匹配逻辑,支持同卡匹配多个配置并按 priority 合并 interval
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 7m27s
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 7m27s
核心变更: - MatchConfig 改为 MatchConfigs,返回所有匹配配置 - MergedTaskIntervals 按 task type 合并各配置,选取最高优先级(非 nil 且最小 priority 值) - hasAnyEnabledInterval 过滤所有 interval 均为 NULL 的配置 - calcInitialDelay 重构为纯函数,接收 interval 参数 - 移除 getEnabledTaskTypes 和 getIntervalByTaskType(被 MergedTaskIntervals 替代) - scheduler.go 新增心跳 key + 顶层 panic recovery + Init 完成守卫 - initializer.go 批量失败日志升级为 Error,逐条检查 Pipeline 命令错误 - 数据迁移:禁用 id=29 的轮询配置(所有 interval 均为 NULL) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -102,20 +102,18 @@ func (b *PollingBase) requeueCard(ctx context.Context, cardID uint, taskType str
|
||||
return b.queueMgr.Requeue(ctx, cardID, taskType, time.Now().Add(30*time.Second))
|
||||
}
|
||||
|
||||
cfg := b.configMgr.MatchConfig(card)
|
||||
if cfg == nil {
|
||||
// 兜底:配置未加载(DB 暂时不可达)时延迟 30 秒重入队,防止卡从轮询永久消失
|
||||
intervals := b.configMgr.MergedTaskIntervals(card)
|
||||
if len(intervals) == 0 {
|
||||
// 兜底:配置未加载时延迟 30 秒重入队,防止卡从轮询永久消失
|
||||
b.logger.Warn("无匹配轮询配置,30秒后重入队(配置可能未加载)",
|
||||
zap.Uint("card_id", cardID), zap.String("task_type", taskType))
|
||||
return b.queueMgr.Requeue(ctx, cardID, taskType, time.Now().Add(30*time.Second))
|
||||
}
|
||||
|
||||
interval := getIntervalByTaskType(cfg, taskType)
|
||||
if interval <= 0 {
|
||||
info, ok := intervals[taskType]
|
||||
if !ok || info.Interval <= 0 {
|
||||
b.logger.Debug("轮询间隔为 NULL,不入队", zap.Uint("card_id", cardID), zap.String("task_type", taskType))
|
||||
return nil
|
||||
}
|
||||
|
||||
nextCheckAt := time.Now().Add(time.Duration(interval) * time.Second)
|
||||
nextCheckAt := time.Now().Add(time.Duration(info.Interval) * time.Second)
|
||||
return b.queueMgr.Requeue(ctx, cardID, taskType, nextCheckAt)
|
||||
}
|
||||
|
||||
@@ -7,38 +7,8 @@ import (
|
||||
"github.com/bytedance/sonic"
|
||||
"go.uber.org/zap"
|
||||
"gorm.io/gorm"
|
||||
|
||||
"github.com/break/junhong_cmp_fiber/internal/model"
|
||||
"github.com/break/junhong_cmp_fiber/pkg/constants"
|
||||
)
|
||||
|
||||
// getIntervalByTaskType 从配置中提取指定任务类型的轮询间隔(秒)
|
||||
func getIntervalByTaskType(cfg *model.PollingConfig, taskType string) int {
|
||||
switch taskType {
|
||||
case constants.TaskTypePollingRealname:
|
||||
if cfg.RealnameCheckInterval != nil && *cfg.RealnameCheckInterval > 0 {
|
||||
return *cfg.RealnameCheckInterval
|
||||
}
|
||||
case constants.TaskTypePollingCarddata:
|
||||
if cfg.CarddataCheckInterval != nil && *cfg.CarddataCheckInterval > 0 {
|
||||
return *cfg.CarddataCheckInterval
|
||||
}
|
||||
case constants.TaskTypePollingPackage:
|
||||
if cfg.PackageCheckInterval != nil && *cfg.PackageCheckInterval > 0 {
|
||||
return *cfg.PackageCheckInterval
|
||||
}
|
||||
case constants.TaskTypePollingProtect:
|
||||
if cfg.ProtectCheckInterval != nil && *cfg.ProtectCheckInterval > 0 {
|
||||
return *cfg.ProtectCheckInterval
|
||||
}
|
||||
case constants.TaskTypePollingCardStatus:
|
||||
if cfg.CardStatusCheckInterval != nil && *cfg.CardStatusCheckInterval > 0 {
|
||||
return *cfg.CardStatusCheckInterval
|
||||
}
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
// shortTaskType 从完整任务类型中提取简短名称(如 polling:carddata → carddata)
|
||||
func shortTaskType(fullTaskType string) string {
|
||||
for i := len(fullTaskType) - 1; i >= 0; i-- {
|
||||
|
||||
Reference in New Issue
Block a user