diff --git a/common/constants.go b/common/constants.go index 49077a17..1dc5d440 100644 --- a/common/constants.go +++ b/common/constants.go @@ -58,6 +58,8 @@ var EmailDomainWhitelist = []string{ "foxmail.com", } +var AutoReEnableFailedChannel = false + var DebugEnabled = os.Getenv("DEBUG") == "true" var MemoryCacheEnabled = os.Getenv("MEMORY_CACHE_ENABLED") == "true" diff --git a/controller/channel-test.go b/controller/channel-test.go index f9b31a1d..9fa8ac29 100644 --- a/controller/channel-test.go +++ b/controller/channel-test.go @@ -218,6 +218,11 @@ func disableChannel(channelId int, channelName string, reason string) { } } +// enable +func enableChannel(channelId int, channelName string) { + model.UpdateChannelStatusById(channelId, common.ChannelStatusEnabled) +} + func testAllChannels(notify bool) error { if common.RootUserEmail == "" { common.RootUserEmail = model.GetRootUserEmail() @@ -250,9 +255,10 @@ func testAllChannels(notify bool) error { if milliseconds > disableThreshold { err = errors.New(fmt.Sprintf("响应时间 %.2fs 超过阈值 %.2fs", float64(milliseconds)/1000.0, float64(disableThreshold)/1000.0)) disableChannel(channel.Id, channel.Name, err.Error()) - } - if shouldDisableChannel(openaiErr, -1) { + } else if shouldDisableChannel(openaiErr, -1) { disableChannel(channel.Id, channel.Name, err.Error()) + } else if err == nil && openaiErr == nil && channel.Status == common.ChannelStatusAutoDisabled && common.AutoReEnableFailedChannel { + enableChannel(channel.Id, channel.Name) } channel.UpdateResponseTime(milliseconds) time.Sleep(common.RequestInterval) diff --git a/model/option.go b/model/option.go index 627843ea..0daf8966 100644 --- a/model/option.go +++ b/model/option.go @@ -35,6 +35,7 @@ func InitOptionMap() { common.OptionMap["GoogleOAuthEnabled"] = strconv.FormatBool(common.GoogleOAuthEnabled) common.OptionMap["TurnstileCheckEnabled"] = strconv.FormatBool(common.TurnstileCheckEnabled) common.OptionMap["RegisterEnabled"] = strconv.FormatBool(common.RegisterEnabled) + common.OptionMap["AutoReEnableFailedChannel"] = strconv.FormatBool(common.AutoReEnableFailedChannel) common.OptionMap["AutomaticDisableChannelEnabled"] = strconv.FormatBool(common.AutomaticDisableChannelEnabled) common.OptionMap["ApproximateTokenEnabled"] = strconv.FormatBool(common.ApproximateTokenEnabled) common.OptionMap["LogConsumeEnabled"] = strconv.FormatBool(common.LogConsumeEnabled) @@ -157,6 +158,8 @@ func updateOptionMap(key string, value string) (err error) { common.EmailDomainRestrictionEnabled = boolValue case "AutomaticDisableChannelEnabled": common.AutomaticDisableChannelEnabled = boolValue + case "AutoReEnableFailedChannel": + common.AutoReEnableFailedChannel = boolValue case "ApproximateTokenEnabled": common.ApproximateTokenEnabled = boolValue case "LogConsumeEnabled": diff --git a/web/src/components/OperationSetting.js b/web/src/components/OperationSetting.js index bf8b5ffd..a3fdb809 100644 --- a/web/src/components/OperationSetting.js +++ b/web/src/components/OperationSetting.js @@ -15,6 +15,7 @@ const OperationSetting = () => { TopUpLink: '', ChatLink: '', QuotaPerUnit: 0, + AutoReEnableFailedChannel: '', AutomaticDisableChannelEnabled: '', ChannelDisableThreshold: 0, LogConsumeEnabled: '', @@ -269,6 +270,12 @@ const OperationSetting = () => { name='AutomaticDisableChannelEnabled' onChange={handleInputChange} /> +