code refactor: exec pull_prom early

This commit is contained in:
Ulric Qin 2021-08-15 10:28:37 +08:00
parent 60a964ae55
commit 1eecb324d0
1 changed files with 6 additions and 2 deletions

View File

@ -47,13 +47,16 @@ func (re RuleEval) start() {
if re.R.PullExpr.EvaluationInterval <= 0 {
re.R.PullExpr.EvaluationInterval = DEFAULT_PULL_ALERT_INTERVAL
}
sleepDuration := time.Duration(re.R.PullExpr.EvaluationInterval) * time.Second
for {
select {
case <-re.ctx.Done():
return
case <-re.quiteChan:
return
case <-time.After(time.Duration(re.R.PullExpr.EvaluationInterval) * time.Second):
default:
}
// 获取backend的prometheus DataSource
@ -67,8 +70,9 @@ func (re RuleEval) start() {
promVector := pb.QueryVector(re.R.PullExpr.PromQl)
handlePromqlVector(promVector, re.R)
}
time.Sleep(sleepDuration)
}
}(re)
}