feat: establish Orbit models, migrations and development baseline
This commit is contained in:
33
pulse/model/policy.go
Normal file
33
pulse/model/policy.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"time"
|
||||
)
|
||||
|
||||
// RetryPolicy 保存到受理时冻结的策略快照,时长统一使用毫秒。
|
||||
// MaxAttempts 包含首次尝试,不能理解为首次之外的重试次数。
|
||||
type RetryPolicy struct {
|
||||
// MaxAttempts 最多执行尝试数,包含首次尝试。
|
||||
MaxAttempts uint32 `json:"max_attempts"`
|
||||
// InitialDelayMS 首次重试前的等待时长,单位毫秒。
|
||||
InitialDelayMS uint64 `json:"initial_delay_ms"`
|
||||
// MaxDelayMS 重试等待时长上限,单位毫秒。
|
||||
MaxDelayMS uint64 `json:"max_delay_ms"`
|
||||
// AttemptTimeoutMS 单次执行尝试的超时时长,单位毫秒。
|
||||
AttemptTimeoutMS uint64 `json:"attempt_timeout_ms"`
|
||||
}
|
||||
|
||||
func (p RetryPolicy) Validate() error {
|
||||
maxMS := uint64((1<<63 - 1) / int64(time.Millisecond))
|
||||
if p.MaxAttempts == 0 || p.AttemptTimeoutMS == 0 || p.AttemptTimeoutMS > maxMS {
|
||||
return errors.New("finite attempt count and representable positive timeout required")
|
||||
}
|
||||
if p.InitialDelayMS > p.MaxDelayMS || p.MaxDelayMS > maxMS {
|
||||
return errors.New("invalid retry delay range")
|
||||
}
|
||||
if p.MaxAttempts > 1 && p.InitialDelayMS == 0 {
|
||||
return errors.New("retry delay must be positive")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user