3 Star 0 Fork 1

Gitee 极速下载/GoAlert

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/target/goalert
克隆/下载
rulescalculator.go 1.53 KB
一键复制 编辑 原始数据 按行查看 历史
package oncall
import "time"
// RulesCalculator provides a single interface for calculating active users of a set of ResolvedRules.
type RulesCalculator struct {
*TimeIterator
rules []*SingleRuleCalculator
userIDs []string
changed bool
}
// NewRulesCalculator will create a new RulesCalculator bound to the TimeIterator.
func (t *TimeIterator) NewRulesCalculator(loc *time.Location, rules []ResolvedRule) *RulesCalculator {
calc := &RulesCalculator{
TimeIterator: t,
}
for _, r := range rules {
calc.rules = append(calc.rules, t.NewSingleRuleCalculator(loc, r))
}
t.Register(calc)
return calc
}
// Process implements the SubIterator.Process method.
func (rCalc *RulesCalculator) Process(int64) int64 {
rCalc.changed = false
for _, r := range rCalc.rules {
if !r.Changed() {
continue
}
rCalc.changed = true
break
}
// no rules changed, abort
if !rCalc.changed {
return 0
}
rCalc.userIDs = rCalc.userIDs[:0]
for _, r := range rCalc.rules {
id := r.ActiveUser()
if id == "" {
continue
}
rCalc.userIDs = append(rCalc.userIDs, id)
}
return 0
}
// Done implements the SubIterator.Done method.
func (rCalc *RulesCalculator) Done() {}
// ActiveUsers returns the current set of active users for the current timestamp.
// It is only valid until the following Next() call and should not be modified.
func (rCalc *RulesCalculator) ActiveUsers() []string { return rCalc.userIDs }
// Changed will return true if there has been any change this tick.
func (rCalc *RulesCalculator) Changed() bool { return rCalc.changed }
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/mirrors/GoAlert.git
git@gitee.com:mirrors/GoAlert.git
mirrors
GoAlert
GoAlert
master

搜索帮助