feat: support AutoReEnableFailedChannel
This commit is contained in:
parent
e81444b74c
commit
5842f59191
@ -58,6 +58,8 @@ var EmailDomainWhitelist = []string{
|
|||||||
"foxmail.com",
|
"foxmail.com",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var AutoReEnableFailedChannel = false
|
||||||
|
|
||||||
var DebugEnabled = os.Getenv("DEBUG") == "true"
|
var DebugEnabled = os.Getenv("DEBUG") == "true"
|
||||||
var MemoryCacheEnabled = os.Getenv("MEMORY_CACHE_ENABLED") == "true"
|
var MemoryCacheEnabled = os.Getenv("MEMORY_CACHE_ENABLED") == "true"
|
||||||
|
|
||||||
|
@ -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 {
|
func testAllChannels(notify bool) error {
|
||||||
if common.RootUserEmail == "" {
|
if common.RootUserEmail == "" {
|
||||||
common.RootUserEmail = model.GetRootUserEmail()
|
common.RootUserEmail = model.GetRootUserEmail()
|
||||||
@ -250,9 +255,10 @@ func testAllChannels(notify bool) error {
|
|||||||
if milliseconds > disableThreshold {
|
if milliseconds > disableThreshold {
|
||||||
err = errors.New(fmt.Sprintf("响应时间 %.2fs 超过阈值 %.2fs", float64(milliseconds)/1000.0, float64(disableThreshold)/1000.0))
|
err = errors.New(fmt.Sprintf("响应时间 %.2fs 超过阈值 %.2fs", float64(milliseconds)/1000.0, float64(disableThreshold)/1000.0))
|
||||||
disableChannel(channel.Id, channel.Name, err.Error())
|
disableChannel(channel.Id, channel.Name, err.Error())
|
||||||
}
|
} else if shouldDisableChannel(openaiErr, -1) {
|
||||||
if shouldDisableChannel(openaiErr, -1) {
|
|
||||||
disableChannel(channel.Id, channel.Name, err.Error())
|
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)
|
channel.UpdateResponseTime(milliseconds)
|
||||||
time.Sleep(common.RequestInterval)
|
time.Sleep(common.RequestInterval)
|
||||||
|
@ -35,6 +35,7 @@ func InitOptionMap() {
|
|||||||
common.OptionMap["GoogleOAuthEnabled"] = strconv.FormatBool(common.GoogleOAuthEnabled)
|
common.OptionMap["GoogleOAuthEnabled"] = strconv.FormatBool(common.GoogleOAuthEnabled)
|
||||||
common.OptionMap["TurnstileCheckEnabled"] = strconv.FormatBool(common.TurnstileCheckEnabled)
|
common.OptionMap["TurnstileCheckEnabled"] = strconv.FormatBool(common.TurnstileCheckEnabled)
|
||||||
common.OptionMap["RegisterEnabled"] = strconv.FormatBool(common.RegisterEnabled)
|
common.OptionMap["RegisterEnabled"] = strconv.FormatBool(common.RegisterEnabled)
|
||||||
|
common.OptionMap["AutoReEnableFailedChannel"] = strconv.FormatBool(common.AutoReEnableFailedChannel)
|
||||||
common.OptionMap["AutomaticDisableChannelEnabled"] = strconv.FormatBool(common.AutomaticDisableChannelEnabled)
|
common.OptionMap["AutomaticDisableChannelEnabled"] = strconv.FormatBool(common.AutomaticDisableChannelEnabled)
|
||||||
common.OptionMap["ApproximateTokenEnabled"] = strconv.FormatBool(common.ApproximateTokenEnabled)
|
common.OptionMap["ApproximateTokenEnabled"] = strconv.FormatBool(common.ApproximateTokenEnabled)
|
||||||
common.OptionMap["LogConsumeEnabled"] = strconv.FormatBool(common.LogConsumeEnabled)
|
common.OptionMap["LogConsumeEnabled"] = strconv.FormatBool(common.LogConsumeEnabled)
|
||||||
@ -157,6 +158,8 @@ func updateOptionMap(key string, value string) (err error) {
|
|||||||
common.EmailDomainRestrictionEnabled = boolValue
|
common.EmailDomainRestrictionEnabled = boolValue
|
||||||
case "AutomaticDisableChannelEnabled":
|
case "AutomaticDisableChannelEnabled":
|
||||||
common.AutomaticDisableChannelEnabled = boolValue
|
common.AutomaticDisableChannelEnabled = boolValue
|
||||||
|
case "AutoReEnableFailedChannel":
|
||||||
|
common.AutoReEnableFailedChannel = boolValue
|
||||||
case "ApproximateTokenEnabled":
|
case "ApproximateTokenEnabled":
|
||||||
common.ApproximateTokenEnabled = boolValue
|
common.ApproximateTokenEnabled = boolValue
|
||||||
case "LogConsumeEnabled":
|
case "LogConsumeEnabled":
|
||||||
|
@ -15,6 +15,7 @@ const OperationSetting = () => {
|
|||||||
TopUpLink: '',
|
TopUpLink: '',
|
||||||
ChatLink: '',
|
ChatLink: '',
|
||||||
QuotaPerUnit: 0,
|
QuotaPerUnit: 0,
|
||||||
|
AutoReEnableFailedChannel: '',
|
||||||
AutomaticDisableChannelEnabled: '',
|
AutomaticDisableChannelEnabled: '',
|
||||||
ChannelDisableThreshold: 0,
|
ChannelDisableThreshold: 0,
|
||||||
LogConsumeEnabled: '',
|
LogConsumeEnabled: '',
|
||||||
@ -269,6 +270,12 @@ const OperationSetting = () => {
|
|||||||
name='AutomaticDisableChannelEnabled'
|
name='AutomaticDisableChannelEnabled'
|
||||||
onChange={handleInputChange}
|
onChange={handleInputChange}
|
||||||
/>
|
/>
|
||||||
|
<Form.Checkbox
|
||||||
|
checked={inputs.AutoReEnableFailedChannel === 'true'}
|
||||||
|
label='重新启用之前被自动禁用的故障通道 '
|
||||||
|
name='AutoReEnableFailedChannel'
|
||||||
|
onChange={handleInputChange}
|
||||||
|
/>
|
||||||
</Form.Group>
|
</Form.Group>
|
||||||
<Form.Button onClick={() => {
|
<Form.Button onClick={() => {
|
||||||
submitConfig('monitor').then();
|
submitConfig('monitor').then();
|
||||||
|
Loading…
Reference in New Issue
Block a user