Просмотр исходного кода

feat: 只自动启用被自动禁用的渠道 (close #224)

CaIon 1 год назад
Родитель
Сommit
ecd06cf2f8
2 измененных файлов с 5 добавлено и 2 удалено
  1. 1 1
      controller/channel-test.go
  2. 4 1
      service/channel.go

+ 1 - 1
controller/channel-test.go

@@ -208,7 +208,7 @@ func testAllChannels(notify bool) error {
 			if isChannelEnabled && service.ShouldDisableChannel(openaiErr, -1) && ban {
 				service.DisableChannel(channel.Id, channel.Name, err.Error())
 			}
-			if !isChannelEnabled && service.ShouldEnableChannel(err, openaiErr) {
+			if !isChannelEnabled && service.ShouldEnableChannel(err, openaiErr, channel.Status) {
 				service.EnableChannel(channel.Id, channel.Name)
 			}
 			channel.UpdateResponseTime(milliseconds)

+ 4 - 1
service/channel.go

@@ -63,7 +63,7 @@ func ShouldDisableChannel(err *relaymodel.OpenAIError, statusCode int) bool {
 	return false
 }
 
-func ShouldEnableChannel(err error, openAIErr *relaymodel.OpenAIError) bool {
+func ShouldEnableChannel(err error, openAIErr *relaymodel.OpenAIError, status int) bool {
 	if !common.AutomaticEnableChannelEnabled {
 		return false
 	}
@@ -73,5 +73,8 @@ func ShouldEnableChannel(err error, openAIErr *relaymodel.OpenAIError) bool {
 	if openAIErr != nil {
 		return false
 	}
+	if status != common.ChannelStatusAutoDisabled {
+		return false
+	}
 	return true
 }