并发监控修复
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 8m20s

This commit is contained in:
2026-08-10 16:58:33 +08:00
parent f15a64395f
commit 77ce9db722
7 changed files with 102 additions and 3 deletions

View File

@@ -2,6 +2,7 @@ package polling
import (
"context"
"strings"
"time"
"github.com/redis/go-redis/v9"
@@ -63,7 +64,7 @@ func (s *ConcurrencyService) List(ctx context.Context) ([]*ConcurrencyStatus, er
}
// 从 Redis 获取当前并发数
currentKey := constants.RedisPollingConcurrencyCurrentKey(cfg.TaskType)
currentKey := pollingConcurrencyCurrentKey(cfg.TaskType)
current, err := s.redis.Get(ctx, currentKey).Int64()
if err != nil && err != redis.Nil {
current = 0
@@ -98,7 +99,7 @@ func (s *ConcurrencyService) GetByTaskType(ctx context.Context, taskType string)
}
// 从 Redis 获取当前并发数
currentKey := constants.RedisPollingConcurrencyCurrentKey(cfg.TaskType)
currentKey := pollingConcurrencyCurrentKey(cfg.TaskType)
current, err := s.redis.Get(ctx, currentKey).Int64()
if err != nil && err != redis.Nil {
current = 0
@@ -176,7 +177,7 @@ func (s *ConcurrencyService) ResetConcurrency(ctx context.Context, taskType stri
}
// 重置 Redis 当前计数为 0
currentKey := constants.RedisPollingConcurrencyCurrentKey(taskType)
currentKey := pollingConcurrencyCurrentKey(config.TaskType)
before, getErr := s.redis.Get(ctx, currentKey).Int64()
beforeExists := getErr == nil
if getErr != nil && getErr != redis.Nil {
@@ -257,6 +258,14 @@ func (s *ConcurrencyService) SyncConfigToRedis(ctx context.Context, config *mode
return s.redis.Set(ctx, configKey, config.MaxConcurrency, 24*time.Hour).Err()
}
// pollingConcurrencyCurrentKey 将配置中的短任务类型转换为 Worker 使用的完整计数键。
func pollingConcurrencyCurrentKey(taskType string) string {
if !strings.HasPrefix(taskType, "polling:") {
taskType = "polling:" + taskType
}
return constants.RedisPollingConcurrencyCurrentKey(taskType)
}
// getTaskTypeName 获取任务类型的中文名称
func (s *ConcurrencyService) getTaskTypeName(taskType string) string {
switch taskType {