diff --git a/internal/config/backoff.go b/internal/config/backoff.go new file mode 100644 index 0000000..0195e71 --- /dev/null +++ b/internal/config/backoff.go @@ -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, + } +} diff --git a/internal/config/config.go b/internal/config/config.go index 1c41c41..54d828d 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -66,4 +66,5 @@ func init() { } initLog() + initBackoff() } diff --git a/internal/config/models.go b/internal/config/models.go index 1ed2449..05de3c9 100644 --- a/internal/config/models.go +++ b/internal/config/models.go @@ -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 {