From 88bbc452a7ce5dc502a675ff250072d44b0acf45 Mon Sep 17 00:00:00 2001 From: Marcus Efraimsson Date: Fri, 28 Sep 2018 11:14:36 +0200 Subject: [PATCH] wip: send and mark as complete --- pkg/models/alert_notifications.go | 5 +++-- pkg/services/alerting/notifier.go | 25 ++++++++++++++++++------- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/pkg/models/alert_notifications.go b/pkg/models/alert_notifications.go index b46a09ea345..5f7532576c0 100644 --- a/pkg/models/alert_notifications.go +++ b/pkg/models/alert_notifications.go @@ -100,8 +100,9 @@ type SetAlertNotificationStateToPendingCommand struct { } type SetAlertNotificationStateToCompleteCommand struct { - Id int64 - SentAt int64 + Id int64 + Version int64 + SentAt int64 } type GetNotificationStateQuery struct { diff --git a/pkg/services/alerting/notifier.go b/pkg/services/alerting/notifier.go index d9d0e278e99..0de2abc9e0a 100644 --- a/pkg/services/alerting/notifier.go +++ b/pkg/services/alerting/notifier.go @@ -3,6 +3,7 @@ package alerting import ( "errors" "fmt" + "time" "github.com/grafana/grafana/pkg/bus" "github.com/grafana/grafana/pkg/components/imguploader" @@ -53,17 +54,27 @@ func (n *notificationService) SendIfNeeded(context *EvalContext) error { } } - // get alert notification (version = 1) - // phantomjs 15 sek - // loopa notifier - ge mig ett lås! where version = 1 - // send notification - // Släpp lås - // - return n.sendNotifications(context, notifierStates) } func (n *notificationService) sendAndMarkAsComplete(evalContext *EvalContext, notifierState *NotifierState) error { + err := notifierState.notifier.Notify(evalContext) + + cmd := &m.SetAlertNotificationStateToCompleteCommand{ + Id: notifierState.state.Id, + Version: notifierState.state.Version, + SentAt: time.Now().Unix(), + } + + err = bus.DispatchCtx(evalContext.Ctx, cmd) + if err == m.ErrAlertNotificationStateVersionConflict { + return nil + } + + if err != nil { + return err + } + return nil }