Fix CPU usage hopefully
ci/woodpecker/push/build Pipeline was successful
Details
ci/woodpecker/push/build Pipeline was successful
Details
This commit is contained in:
parent
9531bd95de
commit
a37b641a9b
|
|
@ -6,16 +6,20 @@ import (
|
|||
)
|
||||
|
||||
func (s *Server) StartAlerts() {
|
||||
ticker := time.NewTicker(time.Second * 1)
|
||||
|
||||
go func() {
|
||||
for {
|
||||
interval := time.Second * 5
|
||||
startedAt := time.Now()
|
||||
|
||||
err := s.Services.AlertsEvaluator.EvaluateAlerts()
|
||||
if err != nil {
|
||||
fmt.Println("Error evaluating alerts: ", err)
|
||||
}
|
||||
|
||||
<-ticker.C
|
||||
elapsed := time.Since(startedAt)
|
||||
if elapsed < interval {
|
||||
time.Sleep(interval - elapsed)
|
||||
}
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -157,8 +157,11 @@ func (s *AlertsEvaluatorService) EvaluateAlert(alert *models.AlertItem) error {
|
|||
}
|
||||
}
|
||||
|
||||
if newStatus != alert.LastStatus || newStatus == models.AlertStatusOk {
|
||||
s.ctx.DB.Exec("UPDATE alerts SET last_status = ?, last_status_at = ? WHERE id = ?", newStatus, time.Now().Unix(), alert.Id)
|
||||
if newStatus != alert.LastStatus {
|
||||
_, err := s.ctx.DB.Exec("UPDATE alerts SET last_status = ?, last_status_at = ? WHERE id = ?", newStatus, time.Now().Unix(), alert.Id)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error updating alert status: %v", err)
|
||||
}
|
||||
|
||||
if newStatus == models.AlertStatusAlerting || newStatus == models.AlertStatusOk {
|
||||
sensor, err := s.ctx.Services.Sensors.GetById(sensorId)
|
||||
|
|
|
|||
Loading…
Reference in New Issue