Chore: Fix pass context for SetAlertStateCommand (#42135) (#42146)

* fix pass ctx for SetAlertStateCommand

* fix integration test

(cherry picked from commit 96b1776856)

Co-authored-by: Will Browne <wbrowne@users.noreply.github.com>
This commit is contained in:
Grot (@grafanabot)
2021-11-25 10:32:52 +01:00
committed by GitHub
co-authored by Will Browne
parent 53140c5b50
commit d91b6f9c67
3 changed files with 6 additions and 6 deletions
+3 -3
View File
@@ -19,7 +19,7 @@ func (ss *SQLStore) addAlertQueryAndCommandHandlers() {
bus.AddHandlerCtx("sql", ss.HandleAlertsQuery)
bus.AddHandlerCtx("sql", ss.GetAlertById)
bus.AddHandlerCtx("sql", ss.GetAllAlertQueryHandler)
bus.AddHandlerCtx("sql", SetAlertState)
bus.AddHandlerCtx("sql", ss.SetAlertState)
bus.AddHandlerCtx("sql", ss.GetAlertStatesForDashboard)
bus.AddHandlerCtx("sql", PauseAlert)
bus.AddHandlerCtx("sql", PauseAllAlerts)
@@ -305,8 +305,8 @@ func GetAlertsByDashboardId2(dashboardId int64, sess *DBSession) ([]*models.Aler
return alerts, nil
}
func SetAlertState(ctx context.Context, cmd *models.SetAlertStateCommand) error {
return inTransaction(func(sess *DBSession) error {
func (ss *SQLStore) SetAlertState(ctx context.Context, cmd *models.SetAlertStateCommand) error {
return ss.WithTransactionalDbSession(ctx, func(sess *DBSession) error {
alert := models.Alert{}
if has, err := sess.ID(cmd.AlertId).Get(&alert); err != nil {
+2 -2
View File
@@ -83,7 +83,7 @@ func TestAlertingDataAccess(t *testing.T) {
State: models.AlertStateOK,
}
err := SetAlertState(context.Background(), cmd)
err := sqlStore.SetAlertState(context.Background(), cmd)
require.Nil(t, err)
})
@@ -100,7 +100,7 @@ func TestAlertingDataAccess(t *testing.T) {
State: models.AlertStateOK,
}
err = SetAlertState(context.Background(), cmd)
err = sqlStore.SetAlertState(context.Background(), cmd)
require.Error(t, err)
})