feat: backoff config initial func

This commit is contained in:
Mmx
2024-09-24 23:18:42 +08:00
parent f82deb2870
commit e1ff68cfc2
3 changed files with 36 additions and 2 deletions

View File

@@ -0,0 +1,22 @@
package config
import (
"github.com/Mmx233/BackoffCli/backoff"
"time"
)
var BackoffConfig backoff.Conf
func initBackoff() {
setting := Settings.Guardian.Backoff
BackoffConfig = backoff.Conf{
Logger: Logger,
DisableRecovery: true,
InitialDuration: time.Duration(setting.InitialDuration) * time.Second,
MaxDuration: time.Duration(setting.MaxDuration) * time.Second,
MaxRetry: setting.MaxRetries,
ExponentFactor: int(setting.ExponentFactor),
InterConstFactor: time.Duration(setting.InterConstFactor) * time.Second,
OuterConstFactor: time.Duration(setting.OuterConstFactor) * time.Second,
}
}

View File

@@ -66,4 +66,5 @@ func init() {
}
initLog()
initBackoff()
}

View File

@@ -8,8 +8,19 @@ import (
type (
GuardianConf struct {
Enable bool `json:"enable" yaml:"enable"`
Duration uint `json:"duration" yaml:"duration"`
Enable bool `json:"enable" yaml:"enable"`
Duration uint `json:"duration" yaml:"duration"`
Backoff BackoffConf `json:"backoff" yaml:"backoff"`
}
BackoffConf struct {
MaxRetries uint `json:"max_retries" yaml:"max_retries"`
InitialDuration uint `json:"initial_duration" yaml:"initial_duration"`
MaxDuration uint `json:"max_duration" yaml:"max_duration"`
ExponentFactor uint `json:"exponent_factor" yaml:"exponent_factor"`
InterConstFactor uint `json:"inter_const_factor" yaml:"inter_const_factor"`
OuterConstFactor uint `json:"outer_const_factor" yaml:"outer_const_factor"`
}
BasicConf struct {