Chore: Fix pass context for SetAlertStateCommand (#42135)

* fix pass ctx for SetAlertStateCommand

* fix integration test
This commit is contained in:
Will Browne 2021-11-23 15:40:09 +00:00 committed by GitHub
parent cec2d965ec
commit 96b1776856
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 6 deletions

View File

@ -58,7 +58,7 @@ func (handler *defaultResultHandler) handle(evalContext *EvalContext) error {
EvalData: annotationData,
}
if err := bus.Dispatch(cmd); err != nil {
if err := bus.DispatchCtx(evalContext.Ctx, cmd); err != nil {
if errors.Is(err, models.ErrCannotChangeStateOnPausedAlert) {
handler.log.Error("Cannot change state on alert that's paused", "error", err)
return err

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 {

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)
})