style(alerting): improve naming

pull/5622/head
bergquist 9 years ago
parent 04436c8a52
commit 3ad90c389c
  1. 7
      pkg/services/alerting/engine.go
  2. 12
      pkg/services/alerting/models.go
  3. 0
      pkg/services/alerting/reader_test.go
  4. 5
      pkg/services/sqlstore/alert_state.go

@ -108,11 +108,10 @@ func (e *Engine) resultHandler() {
result.AlertJob.Running = false
// handle result error
if result.Error != nil {
result.AlertJob.RetryCount++
result.AlertJob.IncRetry()
if result.AlertJob.RetryCount < maxRetries {
if result.AlertJob.Retryable() {
e.log.Error("Alert Rule Result Error", "ruleId", result.AlertJob.Rule.Id, "error", result.Error, "retry", result.AlertJob.RetryCount)
e.execQueue <- result.AlertJob
} else {
@ -123,7 +122,7 @@ func (e *Engine) resultHandler() {
e.saveState(result)
}
} else {
result.AlertJob.RetryCount = 0
result.AlertJob.ResetRetry()
e.saveState(result)
}
}

@ -8,6 +8,18 @@ type AlertJob struct {
Rule *AlertRule
}
func (aj *AlertJob) Retryable() bool {
return aj.RetryCount < maxRetries
}
func (aj *AlertJob) ResetRetry() {
aj.RetryCount = 0
}
func (aj *AlertJob) IncRetry() {
aj.RetryCount++
}
type AlertResult struct {
State string
ActualValue float64

@ -31,13 +31,14 @@ func SetNewAlertState(cmd *m.UpdateAlertStateCommand) error {
}
if alert.State == cmd.NewState {
cmd.Result = &m.Alert{}
return nil
}
alert.State = cmd.NewState
sess.Id(alert.Id).Update(&alert)
log := m.AlertState{
alertState := m.AlertState{
AlertId: cmd.AlertId,
OrgId: cmd.AlertId,
NewState: cmd.NewState,
@ -45,7 +46,7 @@ func SetNewAlertState(cmd *m.UpdateAlertStateCommand) error {
Created: time.Now(),
}
sess.Insert(&log)
sess.Insert(&alertState)
cmd.Result = &alert
return nil

Loading…
Cancel
Save