fix: 代码修复
This commit is contained in:
@@ -149,8 +149,8 @@ func (s *KeyCronService) worker(ctx context.Context, wg *sync.WaitGroup, group *
|
|||||||
for key := range jobs {
|
for key := range jobs {
|
||||||
isValid, validationErr := s.Validator.ValidateSingleKey(ctx, &key, group)
|
isValid, validationErr := s.Validator.ValidateSingleKey(ctx, &key, group)
|
||||||
|
|
||||||
newStatus := key.Status
|
var newStatus string
|
||||||
newErrorReason := key.ErrorReason
|
var newErrorReason string
|
||||||
statusChanged := false
|
statusChanged := false
|
||||||
|
|
||||||
if validationErr != nil {
|
if validationErr != nil {
|
||||||
@@ -161,11 +161,8 @@ func (s *KeyCronService) worker(ctx context.Context, wg *sync.WaitGroup, group *
|
|||||||
// Validation succeeded
|
// Validation succeeded
|
||||||
if isValid {
|
if isValid {
|
||||||
newStatus = "active"
|
newStatus = "active"
|
||||||
newErrorReason = "" // Clear reason on success
|
newErrorReason = ""
|
||||||
} else {
|
} else {
|
||||||
// This case might happen if the key is valid but has no quota, etc.
|
|
||||||
// The error would be in validationErr, so this branch is less likely.
|
|
||||||
// We still mark it as inactive but without a specific error from our side.
|
|
||||||
newStatus = "inactive"
|
newStatus = "inactive"
|
||||||
newErrorReason = "Validation returned false without a specific error."
|
newErrorReason = "Validation returned false without a specific error."
|
||||||
}
|
}
|
||||||
|
@@ -57,12 +57,12 @@ func (s *KeyManualValidationService) StartValidationTask(group *models.Group) (*
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Run the validation in a separate goroutine
|
// Run the validation in a separate goroutine
|
||||||
go s.runValidation(group, keys, taskStatus)
|
go s.runValidation(group, keys)
|
||||||
|
|
||||||
return taskStatus, nil
|
return taskStatus, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *KeyManualValidationService) runValidation(group *models.Group, keys []models.APIKey, task *TaskStatus) {
|
func (s *KeyManualValidationService) runValidation(group *models.Group, keys []models.APIKey) {
|
||||||
logrus.Infof("Starting manual validation for group %s", group.Name)
|
logrus.Infof("Starting manual validation for group %s", group.Name)
|
||||||
|
|
||||||
jobs := make(chan models.APIKey, len(keys))
|
jobs := make(chan models.APIKey, len(keys))
|
||||||
@@ -70,7 +70,7 @@ func (s *KeyManualValidationService) runValidation(group *models.Group, keys []m
|
|||||||
|
|
||||||
concurrency := s.SettingsManager.GetInt("key_validation_concurrency", 10)
|
concurrency := s.SettingsManager.GetInt("key_validation_concurrency", 10)
|
||||||
if concurrency <= 0 {
|
if concurrency <= 0 {
|
||||||
concurrency = 10 // Fallback to a safe default
|
concurrency = 10
|
||||||
}
|
}
|
||||||
|
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
|
Reference in New Issue
Block a user