Simplify the design to update concurrency controller once the rule evaluation has done
Signed-off-by: Marco Pracucci <marco@pracucci.com>
This commit is contained in:
parent
1bb341fa51
commit
21a03dc018
|
@ -437,13 +437,10 @@ func (g *Group) Eval(ctx context.Context, ts time.Time) {
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
|
|
||||||
eval := func(i int, rule Rule, async bool) {
|
eval := func(i int, rule Rule, cleanup func()) {
|
||||||
defer func() {
|
if cleanup != nil {
|
||||||
if async {
|
defer cleanup()
|
||||||
wg.Done()
|
}
|
||||||
g.opts.RuleConcurrencyController.Done()
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
logger := log.WithPrefix(g.logger, "name", rule.Name(), "index", i)
|
logger := log.WithPrefix(g.logger, "name", rule.Name(), "index", i)
|
||||||
ctx, sp := otel.Tracer("").Start(ctx, "rule")
|
ctx, sp := otel.Tracer("").Start(ctx, "rule")
|
||||||
|
@ -576,9 +573,13 @@ func (g *Group) Eval(ctx context.Context, ts time.Time) {
|
||||||
ctrl := g.opts.RuleConcurrencyController
|
ctrl := g.opts.RuleConcurrencyController
|
||||||
if ctrl != nil && ctrl.RuleEligible(g, rule) && ctrl.Allow() {
|
if ctrl != nil && ctrl.RuleEligible(g, rule) && ctrl.Allow() {
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
go eval(i, rule, true)
|
|
||||||
|
go eval(i, rule, func() {
|
||||||
|
wg.Done()
|
||||||
|
g.opts.RuleConcurrencyController.Done()
|
||||||
|
})
|
||||||
} else {
|
} else {
|
||||||
eval(i, rule, false)
|
eval(i, rule, nil)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue