mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Chore: Fix pass context for SetAlertStateCommand (#42135)
* fix pass ctx for SetAlertStateCommand * fix integration test
This commit is contained in:
parent
cec2d965ec
commit
96b1776856
@ -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
|
||||
|
@ -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 {
|
||||
|
@ -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)
|
||||
})
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user