This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user