feat: establish Orbit models, migrations and development baseline
This commit is contained in:
32
weave/model/poll_policy.go
Normal file
32
weave/model/poll_policy.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrPollExhausted = errors.New("poll budget exhausted; reconciliation required")
|
||||
ErrPollInFlight = errors.New("a poll round is still in flight")
|
||||
ErrPollResolved = errors.New("poll already resolved")
|
||||
ErrPollNotDue = errors.New("poll interval has not elapsed")
|
||||
)
|
||||
|
||||
// NextRound 用数据库时间检查已锁定的查询快照。调用方还必须核验执行门控,
|
||||
// 并在同一事务中写入计数、唯一轮次及对应的 Pulse 任务。
|
||||
// 下一查询时间为空表示持久化暂挂,不能视为允许立即发起查询。
|
||||
func (p PollState) NextRound(now time.Time) (uint32, error) {
|
||||
if p.ResolvedAt != nil {
|
||||
return 0, ErrPollResolved
|
||||
}
|
||||
if p.MaxRounds == 0 || p.UsedRounds >= p.MaxRounds || !now.Before(p.DeadlineAt) {
|
||||
return 0, ErrPollExhausted
|
||||
}
|
||||
if p.CurrentTaskID != nil {
|
||||
return 0, ErrPollInFlight
|
||||
}
|
||||
if p.NextPollAt == nil || now.Before(*p.NextPollAt) {
|
||||
return 0, ErrPollNotDue
|
||||
}
|
||||
return p.UsedRounds + 1, nil
|
||||
}
|
||||
Reference in New Issue
Block a user