Rename DispatchCtx to Dispatch (#43563)
This commit is contained in:
@@ -28,7 +28,7 @@ type UsageStatsQuerier interface {
|
||||
// configured in Grafana.
|
||||
func (e *AlertEngine) QueryUsageStats(ctx context.Context) (*UsageStats, error) {
|
||||
cmd := &models.GetAllAlertsQuery{}
|
||||
err := e.Bus.DispatchCtx(ctx, cmd)
|
||||
err := e.Bus.Dispatch(ctx, cmd)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -63,7 +63,7 @@ func (e *AlertEngine) mapRulesToUsageStats(ctx context.Context, rules []*models.
|
||||
result := map[string]int{}
|
||||
for k, v := range typeCount {
|
||||
query := &models.GetDataSourceQuery{Id: k}
|
||||
err := e.Bus.DispatchCtx(ctx, query)
|
||||
err := e.Bus.Dispatch(ctx, query)
|
||||
if err != nil {
|
||||
return map[string]int{}, nil
|
||||
}
|
||||
|
||||
@@ -140,7 +140,7 @@ func (c *QueryCondition) executeQuery(context *alerting.EvalContext, timeRange l
|
||||
OrgId: context.Rule.OrgID,
|
||||
}
|
||||
|
||||
if err := bus.DispatchCtx(context.Ctx, getDsInfo); err != nil {
|
||||
if err := bus.Dispatch(context.Ctx, getDsInfo); err != nil {
|
||||
return nil, fmt.Errorf("could not find datasource: %w", err)
|
||||
}
|
||||
|
||||
|
||||
@@ -108,7 +108,7 @@ func (c *EvalContext) GetDashboardUID() (*models.DashboardRef, error) {
|
||||
}
|
||||
|
||||
uidQuery := &models.GetDashboardRefByIdQuery{Id: c.Rule.DashboardID}
|
||||
if err := bus.DispatchCtx(c.Ctx, uidQuery); err != nil {
|
||||
if err := bus.Dispatch(c.Ctx, uidQuery); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
||||
@@ -48,14 +48,14 @@ func (e *DashAlertExtractor) lookupQueryDataSource(ctx context.Context, panel *s
|
||||
|
||||
if dsName == "" && dsUid == "" {
|
||||
query := &models.GetDefaultDataSourceQuery{OrgId: e.OrgID}
|
||||
if err := bus.DispatchCtx(ctx, query); err != nil {
|
||||
if err := bus.Dispatch(ctx, query); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return query.Result, nil
|
||||
}
|
||||
|
||||
query := &models.GetDataSourceQuery{Name: dsName, Uid: dsUid, OrgId: e.OrgID}
|
||||
if err := bus.DispatchCtx(ctx, query); err != nil {
|
||||
if err := bus.Dispatch(ctx, query); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -208,7 +208,7 @@ func (e *DashAlertExtractor) getAlertFromPanels(ctx context.Context, jsonWithPan
|
||||
Datasources: []*models.DataSource{datasource},
|
||||
}
|
||||
|
||||
if err := bus.DispatchCtx(ctx, &dsFilterQuery); err != nil {
|
||||
if err := bus.Dispatch(ctx, &dsFilterQuery); err != nil {
|
||||
if !errors.Is(err, bus.ErrHandlerNotFound) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -152,7 +152,7 @@ func (n *notificationService) sendAndMarkAsComplete(evalContext *EvalContext, no
|
||||
Version: notifierState.state.Version,
|
||||
}
|
||||
|
||||
return bus.DispatchCtx(evalContext.Ctx, cmd)
|
||||
return bus.Dispatch(evalContext.Ctx, cmd)
|
||||
}
|
||||
|
||||
func (n *notificationService) sendNotification(evalContext *EvalContext, notifierState *notifierState) error {
|
||||
@@ -163,7 +163,7 @@ func (n *notificationService) sendNotification(evalContext *EvalContext, notifie
|
||||
AlertRuleStateUpdatedVersion: evalContext.Rule.StateChanges,
|
||||
}
|
||||
|
||||
err := bus.DispatchCtx(evalContext.Ctx, setPendingCmd)
|
||||
err := bus.Dispatch(evalContext.Ctx, setPendingCmd)
|
||||
if err != nil {
|
||||
if errors.Is(err, models.ErrAlertNotificationStateVersionConflict) {
|
||||
return nil
|
||||
@@ -247,7 +247,7 @@ func (n *notificationService) renderAndUploadImage(evalCtx *EvalContext, timeout
|
||||
func (n *notificationService) getNeededNotifiers(orgID int64, notificationUids []string, evalContext *EvalContext) (notifierStateSlice, error) {
|
||||
query := &models.GetAlertNotificationsWithUidToSendQuery{OrgId: orgID, Uids: notificationUids}
|
||||
|
||||
if err := bus.DispatchCtx(evalContext.Ctx, query); err != nil {
|
||||
if err := bus.Dispatch(evalContext.Ctx, query); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -265,7 +265,7 @@ func (n *notificationService) getNeededNotifiers(orgID int64, notificationUids [
|
||||
OrgId: evalContext.Rule.OrgID,
|
||||
}
|
||||
|
||||
err = bus.DispatchCtx(evalContext.Ctx, query)
|
||||
err = bus.Dispatch(evalContext.Ctx, query)
|
||||
if err != nil {
|
||||
n.log.Error("Could not get notification state.", "notifier", notification.Id, "error", err)
|
||||
continue
|
||||
|
||||
@@ -183,7 +183,7 @@ func (am *AlertmanagerNotifier) Notify(evalContext *alerting.EvalContext) error
|
||||
Body: string(body),
|
||||
}
|
||||
|
||||
if err := bus.DispatchCtx(evalContext.Ctx, cmd); err != nil {
|
||||
if err := bus.Dispatch(evalContext.Ctx, cmd); err != nil {
|
||||
am.log.Error("Failed to send alertmanager", "error", err, "alertmanager", am.Name, "url", url)
|
||||
errCnt++
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ func (dd *DingDingNotifier) Notify(evalContext *alerting.EvalContext) error {
|
||||
Body: string(body),
|
||||
}
|
||||
|
||||
if err := bus.DispatchCtx(evalContext.Ctx, cmd); err != nil {
|
||||
if err := bus.Dispatch(evalContext.Ctx, cmd); err != nil {
|
||||
dd.log.Error("Failed to send DingDing", "error", err, "dingding", dd.Name)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -177,7 +177,7 @@ func (dn *DiscordNotifier) Notify(evalContext *alerting.EvalContext) error {
|
||||
}
|
||||
}
|
||||
|
||||
if err := bus.DispatchCtx(evalContext.Ctx, cmd); err != nil {
|
||||
if err := bus.Dispatch(evalContext.Ctx, cmd); err != nil {
|
||||
dn.log.Error("Failed to send notification to Discord", "error", err)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ func (en *EmailNotifier) Notify(evalContext *alerting.EvalContext) error {
|
||||
}
|
||||
}
|
||||
|
||||
if err := bus.DispatchCtx(evalContext.Ctx, cmd); err != nil {
|
||||
if err := bus.Dispatch(evalContext.Ctx, cmd); err != nil {
|
||||
en.log.Error("Failed to send alert notification email", "error", err)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -220,7 +220,7 @@ func (gcn *GoogleChatNotifier) Notify(evalContext *alerting.EvalContext) error {
|
||||
Body: string(body),
|
||||
}
|
||||
|
||||
if err := bus.DispatchCtx(evalContext.Ctx, cmd); err != nil {
|
||||
if err := bus.Dispatch(evalContext.Ctx, cmd); err != nil {
|
||||
gcn.log.Error("Failed to send Google Hangouts Chat alert", "error", err, "webhook", gcn.Name)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -177,7 +177,7 @@ func (hc *HipChatNotifier) Notify(evalContext *alerting.EvalContext) error {
|
||||
hc.log.Info("Request payload", "json", string(data))
|
||||
cmd := &models.SendWebhookSync{Url: hipURL, Body: string(data)}
|
||||
|
||||
if err := bus.DispatchCtx(evalContext.Ctx, cmd); err != nil {
|
||||
if err := bus.Dispatch(evalContext.Ctx, cmd); err != nil {
|
||||
hc.log.Error("Failed to send hipchat notification", "error", err, "webhook", hc.Name)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -124,7 +124,7 @@ func (kn *KafkaNotifier) Notify(evalContext *alerting.EvalContext) error {
|
||||
},
|
||||
}
|
||||
|
||||
if err := bus.DispatchCtx(evalContext.Ctx, cmd); err != nil {
|
||||
if err := bus.Dispatch(evalContext.Ctx, cmd); err != nil {
|
||||
kn.log.Error("Failed to send notification to Kafka", "error", err, "body", string(body))
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ func (ln *LineNotifier) createAlert(evalContext *alerting.EvalContext) error {
|
||||
Body: form.Encode(),
|
||||
}
|
||||
|
||||
if err := bus.DispatchCtx(evalContext.Ctx, cmd); err != nil {
|
||||
if err := bus.Dispatch(evalContext.Ctx, cmd); err != nil {
|
||||
ln.log.Error("Failed to send notification to LINE", "error", err, "body", body)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -205,7 +205,7 @@ func (on *OpsGenieNotifier) createAlert(evalContext *alerting.EvalContext) error
|
||||
},
|
||||
}
|
||||
|
||||
if err := bus.DispatchCtx(evalContext.Ctx, cmd); err != nil {
|
||||
if err := bus.Dispatch(evalContext.Ctx, cmd); err != nil {
|
||||
on.log.Error("Failed to send notification to OpsGenie", "error", err, "body", string(body))
|
||||
}
|
||||
|
||||
@@ -229,7 +229,7 @@ func (on *OpsGenieNotifier) closeAlert(evalContext *alerting.EvalContext) error
|
||||
},
|
||||
}
|
||||
|
||||
if err := bus.DispatchCtx(evalContext.Ctx, cmd); err != nil {
|
||||
if err := bus.Dispatch(evalContext.Ctx, cmd); err != nil {
|
||||
on.log.Error("Failed to send notification to OpsGenie", "error", err, "body", string(body))
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -240,7 +240,7 @@ func (pn *PagerdutyNotifier) Notify(evalContext *alerting.EvalContext) error {
|
||||
},
|
||||
}
|
||||
|
||||
if err := bus.DispatchCtx(evalContext.Ctx, cmd); err != nil {
|
||||
if err := bus.Dispatch(evalContext.Ctx, cmd); err != nil {
|
||||
pn.log.Error("Failed to send notification to Pagerduty", "error", err, "body", string(body))
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -287,7 +287,7 @@ func (pn *PushoverNotifier) Notify(evalContext *alerting.EvalContext) error {
|
||||
Body: uploadBody.String(),
|
||||
}
|
||||
|
||||
if err := bus.DispatchCtx(evalContext.Ctx, cmd); err != nil {
|
||||
if err := bus.Dispatch(evalContext.Ctx, cmd); err != nil {
|
||||
pn.log.Error("Failed to send pushover notification", "error", err, "webhook", pn.Name)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -146,7 +146,7 @@ func (sn *SensuNotifier) Notify(evalContext *alerting.EvalContext) error {
|
||||
HttpMethod: "POST",
|
||||
}
|
||||
|
||||
if err := bus.DispatchCtx(evalContext.Ctx, cmd); err != nil {
|
||||
if err := bus.Dispatch(evalContext.Ctx, cmd); err != nil {
|
||||
sn.log.Error("Failed to send sensu event", "error", err, "sensu", sn.Name)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -197,7 +197,7 @@ func (sn *SensuGoNotifier) Notify(evalContext *alerting.EvalContext) error {
|
||||
"Authorization": fmt.Sprintf("Key %s", sn.APIKey),
|
||||
},
|
||||
}
|
||||
if err := bus.DispatchCtx(evalContext.Ctx, cmd); err != nil {
|
||||
if err := bus.Dispatch(evalContext.Ctx, cmd); err != nil {
|
||||
sn.log.Error("Failed to send Sensu Go event", "error", err, "sensugo", sn.Name)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -418,7 +418,7 @@ func (sn *SlackNotifier) slackFileUpload(evalContext *alerting.EvalContext, log
|
||||
cmd := &models.SendWebhookSync{
|
||||
Url: "https://slack.com/api/files.upload", Body: uploadBody.String(), HttpHeader: headers, HttpMethod: "POST",
|
||||
}
|
||||
if err := bus.DispatchCtx(evalContext.Ctx, cmd); err != nil {
|
||||
if err := bus.Dispatch(evalContext.Ctx, cmd); err != nil {
|
||||
log.Error("Failed to upload slack image", "error", err, "webhook", "file.upload")
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -135,7 +135,7 @@ func (tn *TeamsNotifier) Notify(evalContext *alerting.EvalContext) error {
|
||||
data, _ := json.Marshal(&body)
|
||||
cmd := &models.SendWebhookSync{Url: tn.URL, Body: string(data)}
|
||||
|
||||
if err := bus.DispatchCtx(evalContext.Ctx, cmd); err != nil {
|
||||
if err := bus.Dispatch(evalContext.Ctx, cmd); err != nil {
|
||||
tn.log.Error("Failed to send teams notification", "error", err, "webhook", tn.Name)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -271,7 +271,7 @@ func (tn *TelegramNotifier) Notify(evalContext *alerting.EvalContext) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := bus.DispatchCtx(evalContext.Ctx, cmd); err != nil {
|
||||
if err := bus.Dispatch(evalContext.Ctx, cmd); err != nil {
|
||||
tn.log.Error("Failed to send webhook", "error", err, "webhook", tn.Name)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -158,7 +158,7 @@ func (notifier *ThreemaNotifier) Notify(evalContext *alerting.EvalContext) error
|
||||
HttpMethod: "POST",
|
||||
HttpHeader: headers,
|
||||
}
|
||||
if err := bus.DispatchCtx(evalContext.Ctx, cmd); err != nil {
|
||||
if err := bus.Dispatch(evalContext.Ctx, cmd); err != nil {
|
||||
notifier.log.Error("Failed to send webhook", "error", err, "webhook", notifier.Name)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -156,7 +156,7 @@ func (vn *VictoropsNotifier) Notify(evalContext *alerting.EvalContext) error {
|
||||
data, _ := bodyJSON.MarshalJSON()
|
||||
cmd := &models.SendWebhookSync{Url: vn.URL, Body: string(data)}
|
||||
|
||||
if err := bus.DispatchCtx(evalContext.Ctx, cmd); err != nil {
|
||||
if err := bus.Dispatch(evalContext.Ctx, cmd); err != nil {
|
||||
vn.log.Error("Failed to send Victorops notification", "error", err, "webhook", vn.Name)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -153,7 +153,7 @@ func (wn *WebhookNotifier) Notify(evalContext *alerting.EvalContext) error {
|
||||
HttpMethod: wn.HTTPMethod,
|
||||
}
|
||||
|
||||
if err := bus.DispatchCtx(evalContext.Ctx, cmd); err != nil {
|
||||
if err := bus.Dispatch(evalContext.Ctx, cmd); err != nil {
|
||||
wn.log.Error("Failed to send webhook", "error", err, "webhook", wn.Name)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ func newRuleReader() *defaultRuleReader {
|
||||
func (arr *defaultRuleReader) fetch(ctx context.Context) []*Rule {
|
||||
cmd := &models.GetAllAlertsQuery{}
|
||||
|
||||
if err := bus.DispatchCtx(ctx, cmd); err != nil {
|
||||
if err := bus.Dispatch(ctx, cmd); err != nil {
|
||||
arr.log.Error("Could not load alerts", "error", err)
|
||||
return []*Rule{}
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ func (handler *defaultResultHandler) handle(evalContext *EvalContext) error {
|
||||
EvalData: annotationData,
|
||||
}
|
||||
|
||||
if err := bus.DispatchCtx(evalContext.Ctx, cmd); err != nil {
|
||||
if err := bus.Dispatch(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
|
||||
|
||||
@@ -226,7 +226,7 @@ func getAlertNotificationUIDByIDAndOrgID(ctx context.Context, notificationID int
|
||||
Id: notificationID,
|
||||
}
|
||||
|
||||
if err := bus.DispatchCtx(ctx, query); err != nil {
|
||||
if err := bus.Dispatch(ctx, query); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
|
||||
@@ -127,7 +127,7 @@ func (srv *CleanUpService) shouldCleanupTempFile(filemtime time.Time, now time.T
|
||||
|
||||
func (srv *CleanUpService) deleteExpiredSnapshots(ctx context.Context) {
|
||||
cmd := models.DeleteExpiredSnapshotsCommand{}
|
||||
if err := bus.DispatchCtx(ctx, &cmd); err != nil {
|
||||
if err := bus.Dispatch(ctx, &cmd); err != nil {
|
||||
srv.log.Error("Failed to delete expired snapshots", "error", err.Error())
|
||||
} else {
|
||||
srv.log.Debug("Deleted expired snapshots", "rows affected", cmd.DeletedRows)
|
||||
@@ -136,7 +136,7 @@ func (srv *CleanUpService) deleteExpiredSnapshots(ctx context.Context) {
|
||||
|
||||
func (srv *CleanUpService) deleteExpiredDashboardVersions(ctx context.Context) {
|
||||
cmd := models.DeleteExpiredVersionsCommand{}
|
||||
if err := bus.DispatchCtx(ctx, &cmd); err != nil {
|
||||
if err := bus.Dispatch(ctx, &cmd); err != nil {
|
||||
srv.log.Error("Failed to delete expired dashboard versions", "error", err.Error())
|
||||
} else {
|
||||
srv.log.Debug("Deleted old/expired dashboard versions", "rows affected", cmd.DeletedRows)
|
||||
@@ -151,7 +151,7 @@ func (srv *CleanUpService) deleteOldLoginAttempts(ctx context.Context) {
|
||||
cmd := models.DeleteOldLoginAttemptsCommand{
|
||||
OlderThan: time.Now().Add(time.Minute * -10),
|
||||
}
|
||||
if err := bus.DispatchCtx(ctx, &cmd); err != nil {
|
||||
if err := bus.Dispatch(ctx, &cmd); err != nil {
|
||||
srv.log.Error("Problem deleting expired login attempts", "error", err.Error())
|
||||
} else {
|
||||
srv.log.Debug("Deleted expired login attempts", "rows affected", cmd.DeletedRows)
|
||||
@@ -164,7 +164,7 @@ func (srv *CleanUpService) expireOldUserInvites(ctx context.Context) {
|
||||
cmd := models.ExpireTempUsersCommand{
|
||||
OlderThan: time.Now().Add(-maxInviteLifetime),
|
||||
}
|
||||
if err := bus.DispatchCtx(ctx, &cmd); err != nil {
|
||||
if err := bus.Dispatch(ctx, &cmd); err != nil {
|
||||
srv.log.Error("Problem expiring user invites", "error", err.Error())
|
||||
} else {
|
||||
srv.log.Debug("Expired user invites", "rows affected", cmd.NumExpired)
|
||||
|
||||
@@ -42,7 +42,7 @@ func (h *ContextHandler) initContextWithJWT(ctx *models.ReqContext, orgId int64)
|
||||
return true
|
||||
}
|
||||
|
||||
if err := bus.DispatchCtx(ctx.Req.Context(), &query); err != nil {
|
||||
if err := bus.Dispatch(ctx.Req.Context(), &query); err != nil {
|
||||
if errors.Is(err, models.ErrUserNotFound) {
|
||||
ctx.Logger.Debug(
|
||||
"Failed to find user using JWT claims",
|
||||
|
||||
@@ -248,7 +248,7 @@ func (auth *AuthProxy) LoginViaLDAP() (int64, error) {
|
||||
SignupAllowed: auth.cfg.LDAPAllowSignup,
|
||||
ExternalUser: extUser,
|
||||
}
|
||||
if err := bus.DispatchCtx(auth.ctx.Req.Context(), upsert); err != nil {
|
||||
if err := bus.Dispatch(auth.ctx.Req.Context(), upsert); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
@@ -305,7 +305,7 @@ func (auth *AuthProxy) LoginViaHeader() (int64, error) {
|
||||
ExternalUser: extUser,
|
||||
}
|
||||
|
||||
err := bus.DispatchCtx(auth.ctx.Req.Context(), upsert)
|
||||
err := bus.Dispatch(auth.ctx.Req.Context(), upsert)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
@@ -334,7 +334,7 @@ func (auth *AuthProxy) GetSignedInUser(userID int64) (*models.SignedInUser, erro
|
||||
UserId: userID,
|
||||
}
|
||||
|
||||
if err := bus.DispatchCtx(context.Background(), query); err != nil {
|
||||
if err := bus.Dispatch(context.Background(), query); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
||||
@@ -146,7 +146,7 @@ func (h *ContextHandler) Middleware(mContext *web.Context) {
|
||||
// update last seen every 5min
|
||||
if reqContext.ShouldUpdateLastSeenAt() {
|
||||
reqContext.Logger.Debug("Updating last user_seen_at", "user_id", reqContext.UserId)
|
||||
if err := bus.DispatchCtx(mContext.Req.Context(), &models.UpdateUserLastSeenAtCommand{UserId: reqContext.UserId}); err != nil {
|
||||
if err := bus.Dispatch(mContext.Req.Context(), &models.UpdateUserLastSeenAtCommand{UserId: reqContext.UserId}); err != nil {
|
||||
reqContext.Logger.Error("Failed to update last_seen_at", "error", err)
|
||||
}
|
||||
}
|
||||
@@ -204,7 +204,7 @@ func (h *ContextHandler) initContextWithAPIKey(reqContext *models.ReqContext) bo
|
||||
|
||||
// fetch key
|
||||
keyQuery := models.GetApiKeyByNameQuery{KeyName: decoded.Name, OrgId: decoded.OrgId}
|
||||
if err := bus.DispatchCtx(reqContext.Req.Context(), &keyQuery); err != nil {
|
||||
if err := bus.Dispatch(reqContext.Req.Context(), &keyQuery); err != nil {
|
||||
reqContext.JsonApiErr(401, InvalidAPIKey, err)
|
||||
return true
|
||||
}
|
||||
@@ -246,7 +246,7 @@ func (h *ContextHandler) initContextWithAPIKey(reqContext *models.ReqContext) bo
|
||||
|
||||
//Use service account linked to API key as the signed in user
|
||||
query := models.GetSignedInUserQuery{UserId: apikey.ServiceAccountId, OrgId: apikey.OrgId}
|
||||
if err := bus.DispatchCtx(reqContext.Req.Context(), &query); err != nil {
|
||||
if err := bus.Dispatch(reqContext.Req.Context(), &query); err != nil {
|
||||
reqContext.Logger.Error(
|
||||
"Failed to link API key to service account in",
|
||||
"id", query.UserId,
|
||||
@@ -286,7 +286,7 @@ func (h *ContextHandler) initContextWithBasicAuth(reqContext *models.ReqContext,
|
||||
Password: password,
|
||||
Cfg: h.Cfg,
|
||||
}
|
||||
if err := bus.DispatchCtx(reqContext.Req.Context(), &authQuery); err != nil {
|
||||
if err := bus.Dispatch(reqContext.Req.Context(), &authQuery); err != nil {
|
||||
reqContext.Logger.Debug(
|
||||
"Failed to authorize the user",
|
||||
"username", username,
|
||||
@@ -303,7 +303,7 @@ func (h *ContextHandler) initContextWithBasicAuth(reqContext *models.ReqContext,
|
||||
user := authQuery.User
|
||||
|
||||
query := models.GetSignedInUserQuery{UserId: user.Id, OrgId: orgID}
|
||||
if err := bus.DispatchCtx(ctx, &query); err != nil {
|
||||
if err := bus.Dispatch(ctx, &query); err != nil {
|
||||
reqContext.Logger.Error(
|
||||
"Failed at user signed in",
|
||||
"id", user.Id,
|
||||
@@ -339,7 +339,7 @@ func (h *ContextHandler) initContextWithToken(reqContext *models.ReqContext, org
|
||||
}
|
||||
|
||||
query := models.GetSignedInUserQuery{UserId: token.UserId, OrgId: orgID}
|
||||
if err := bus.DispatchCtx(ctx, &query); err != nil {
|
||||
if err := bus.Dispatch(ctx, &query); err != nil {
|
||||
reqContext.Logger.Error("Failed to get user with id", "userId", token.UserId, "error", err)
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -324,7 +324,7 @@ func (dr *dashboardServiceImpl) deleteDashboard(ctx context.Context, dashboardId
|
||||
}
|
||||
}
|
||||
cmd := &models.DeleteDashboardCommand{OrgId: orgId, Id: dashboardId}
|
||||
return bus.DispatchCtx(ctx, cmd)
|
||||
return bus.Dispatch(ctx, cmd)
|
||||
}
|
||||
|
||||
func (dr *dashboardServiceImpl) ImportDashboard(ctx context.Context, dto *SaveDashboardDTO) (
|
||||
@@ -353,7 +353,7 @@ func (dr *dashboardServiceImpl) ImportDashboard(ctx context.Context, dto *SaveDa
|
||||
// and provisioned dashboards are left behind but not deleted.
|
||||
func (dr *dashboardServiceImpl) UnprovisionDashboard(ctx context.Context, dashboardId int64) error {
|
||||
cmd := &models.UnprovisionDashboardCommand{Id: dashboardId}
|
||||
return bus.DispatchCtx(ctx, cmd)
|
||||
return bus.Dispatch(ctx, cmd)
|
||||
}
|
||||
|
||||
type FakeDashboardService struct {
|
||||
|
||||
@@ -45,7 +45,7 @@ func (dr *dashboardServiceImpl) GetFolders(ctx context.Context, limit int64, pag
|
||||
Page: page,
|
||||
}
|
||||
|
||||
if err := bus.DispatchCtx(ctx, &searchQuery); err != nil {
|
||||
if err := bus.Dispatch(ctx, &searchQuery); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -209,7 +209,7 @@ func (dr *dashboardServiceImpl) DeleteFolder(ctx context.Context, uid string, fo
|
||||
}
|
||||
|
||||
deleteCmd := models.DeleteDashboardCommand{OrgId: dr.orgId, Id: dashFolder.Id, ForceDeleteFolderRules: forceDeleteRules}
|
||||
if err := bus.DispatchCtx(ctx, &deleteCmd); err != nil {
|
||||
if err := bus.Dispatch(ctx, &deleteCmd); err != nil {
|
||||
return nil, toFolderError(err)
|
||||
}
|
||||
|
||||
@@ -217,7 +217,7 @@ func (dr *dashboardServiceImpl) DeleteFolder(ctx context.Context, uid string, fo
|
||||
}
|
||||
|
||||
func getFolder(ctx context.Context, query models.GetDashboardQuery) (*models.Dashboard, error) {
|
||||
if err := bus.DispatchCtx(ctx, &query); err != nil {
|
||||
if err := bus.Dispatch(ctx, &query); err != nil {
|
||||
return nil, toFolderError(err)
|
||||
}
|
||||
|
||||
|
||||
@@ -204,7 +204,7 @@ func (g *dashboardGuardianImpl) GetAcl() ([]*models.DashboardAclInfoDTO, error)
|
||||
}
|
||||
|
||||
query := models.GetDashboardAclInfoListQuery{DashboardID: g.dashId, OrgID: g.orgId}
|
||||
if err := bus.DispatchCtx(g.ctx, &query); err != nil {
|
||||
if err := bus.Dispatch(g.ctx, &query); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -254,8 +254,8 @@ func (g *dashboardGuardianImpl) getTeams(ctx context.Context) ([]*models.TeamDTO
|
||||
}
|
||||
|
||||
query := models.GetTeamsByUserQuery{OrgId: g.orgId, UserId: g.user.UserId}
|
||||
// TODO: Use bus.DispatchCtx(g.Ctx, &query) when GetTeamsByUserQuery supports context.
|
||||
err := bus.DispatchCtx(ctx, &query)
|
||||
// TODO: Use bus.Dispatch(g.Ctx, &query) when GetTeamsByUserQuery supports context.
|
||||
err := bus.Dispatch(ctx, &query)
|
||||
|
||||
g.teams = query.Result
|
||||
return query.Result, err
|
||||
|
||||
@@ -62,7 +62,7 @@ func (h *DashboardHandler) OnSubscribe(ctx context.Context, user *models.SignedI
|
||||
// make sure can view this dashboard
|
||||
if len(parts) == 2 && parts[0] == "uid" {
|
||||
query := models.GetDashboardQuery{Uid: parts[1], OrgId: user.OrgId}
|
||||
if err := bus.DispatchCtx(ctx, &query); err != nil {
|
||||
if err := bus.Dispatch(ctx, &query); err != nil {
|
||||
logger.Error("Error getting dashboard", "query", query, "error", err)
|
||||
return models.SubscribeReply{}, backend.SubscribeStreamStatusNotFound, nil
|
||||
}
|
||||
@@ -109,7 +109,7 @@ func (h *DashboardHandler) OnPublish(ctx context.Context, user *models.SignedInU
|
||||
return models.PublishReply{}, backend.PublishStreamStatusNotFound, fmt.Errorf("ignore???")
|
||||
}
|
||||
query := models.GetDashboardQuery{Uid: parts[1], OrgId: user.OrgId}
|
||||
if err := bus.DispatchCtx(ctx, &query); err != nil {
|
||||
if err := bus.Dispatch(ctx, &query); err != nil {
|
||||
logger.Error("Unknown dashboard", "query", query)
|
||||
return models.PublishReply{}, backend.PublishStreamStatusNotFound, nil
|
||||
}
|
||||
|
||||
@@ -15,13 +15,13 @@ var getTime = time.Now
|
||||
|
||||
func (s *Implementation) GetExternalUserInfoByLogin(ctx context.Context, query *models.GetExternalUserInfoByLoginQuery) error {
|
||||
userQuery := models.GetUserByLoginQuery{LoginOrEmail: query.LoginOrEmail}
|
||||
err := s.Bus.DispatchCtx(ctx, &userQuery)
|
||||
err := s.Bus.Dispatch(ctx, &userQuery)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
authInfoQuery := &models.GetAuthInfoQuery{UserId: userQuery.Result.Id}
|
||||
if err := s.Bus.DispatchCtx(ctx, authInfoQuery); err != nil {
|
||||
if err := s.Bus.Dispatch(ctx, authInfoQuery); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -81,7 +81,7 @@ func (ls *Implementation) UpsertUser(ctx context.Context, cmd *models.UpsertUser
|
||||
AuthId: extUser.AuthId,
|
||||
OAuthToken: extUser.OAuthToken,
|
||||
}
|
||||
if err := ls.Bus.DispatchCtx(ctx, cmd2); err != nil {
|
||||
if err := ls.Bus.Dispatch(ctx, cmd2); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -103,7 +103,7 @@ func (ls *Implementation) UpsertUser(ctx context.Context, cmd *models.UpsertUser
|
||||
|
||||
if extUser.AuthModule == models.AuthModuleLDAP && user.IsDisabled {
|
||||
// Re-enable user when it found in LDAP
|
||||
if err := ls.Bus.DispatchCtx(ctx, &models.DisableUserCommand{UserId: cmd.Result.Id, IsDisabled: false}); err != nil {
|
||||
if err := ls.Bus.Dispatch(ctx, &models.DisableUserCommand{UserId: cmd.Result.Id, IsDisabled: false}); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -176,7 +176,7 @@ func updateUser(ctx context.Context, user *models.User, extUser *models.External
|
||||
}
|
||||
|
||||
logger.Debug("Syncing user info", "id", user.Id, "update", updateCmd)
|
||||
return bus.DispatchCtx(ctx, updateCmd)
|
||||
return bus.Dispatch(ctx, updateCmd)
|
||||
}
|
||||
|
||||
func updateUserAuth(ctx context.Context, user *models.User, extUser *models.ExternalUserInfo) error {
|
||||
@@ -188,7 +188,7 @@ func updateUserAuth(ctx context.Context, user *models.User, extUser *models.Exte
|
||||
}
|
||||
|
||||
logger.Debug("Updating user_auth info", "user_id", user.Id)
|
||||
return bus.DispatchCtx(ctx, updateCmd)
|
||||
return bus.Dispatch(ctx, updateCmd)
|
||||
}
|
||||
|
||||
func syncOrgRoles(ctx context.Context, user *models.User, extUser *models.ExternalUserInfo) error {
|
||||
@@ -201,7 +201,7 @@ func syncOrgRoles(ctx context.Context, user *models.User, extUser *models.Extern
|
||||
}
|
||||
|
||||
orgsQuery := &models.GetUserOrgListQuery{UserId: user.Id}
|
||||
if err := bus.DispatchCtx(ctx, orgsQuery); err != nil {
|
||||
if err := bus.Dispatch(ctx, orgsQuery); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -218,7 +218,7 @@ func syncOrgRoles(ctx context.Context, user *models.User, extUser *models.Extern
|
||||
} else if extRole != org.Role {
|
||||
// update role
|
||||
cmd := &models.UpdateOrgUserCommand{OrgId: org.OrgId, UserId: user.Id, Role: extRole}
|
||||
if err := bus.DispatchCtx(ctx, cmd); err != nil {
|
||||
if err := bus.Dispatch(ctx, cmd); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -232,7 +232,7 @@ func syncOrgRoles(ctx context.Context, user *models.User, extUser *models.Extern
|
||||
|
||||
// add role
|
||||
cmd := &models.AddOrgUserCommand{UserId: user.Id, Role: orgRole, OrgId: orgId}
|
||||
err := bus.DispatchCtx(ctx, cmd)
|
||||
err := bus.Dispatch(ctx, cmd)
|
||||
if err != nil && !errors.Is(err, models.ErrOrgNotFound) {
|
||||
return err
|
||||
}
|
||||
@@ -243,7 +243,7 @@ func syncOrgRoles(ctx context.Context, user *models.User, extUser *models.Extern
|
||||
logger.Debug("Removing user's organization membership as part of syncing with OAuth login",
|
||||
"userId", user.Id, "orgId", orgId)
|
||||
cmd := &models.RemoveOrgUserCommand{OrgId: orgId, UserId: user.Id}
|
||||
if err := bus.DispatchCtx(ctx, cmd); err != nil {
|
||||
if err := bus.Dispatch(ctx, cmd); err != nil {
|
||||
if errors.Is(err, models.ErrLastOrgAdmin) {
|
||||
logger.Error(err.Error(), "userId", cmd.UserId, "orgId", cmd.OrgId)
|
||||
continue
|
||||
@@ -260,7 +260,7 @@ func syncOrgRoles(ctx context.Context, user *models.User, extUser *models.Extern
|
||||
break
|
||||
}
|
||||
|
||||
return bus.DispatchCtx(ctx, &models.SetUsingOrgCommand{
|
||||
return bus.Dispatch(ctx, &models.SetUsingOrgCommand{
|
||||
UserId: user.Id,
|
||||
OrgId: user.OrgId,
|
||||
})
|
||||
|
||||
@@ -115,7 +115,7 @@ func (dd *DingDingNotifier) Notify(ctx context.Context, as ...*types.Alert) (boo
|
||||
Body: string(body),
|
||||
}
|
||||
|
||||
if err := bus.DispatchCtx(ctx, cmd); err != nil {
|
||||
if err := bus.Dispatch(ctx, cmd); err != nil {
|
||||
return false, fmt.Errorf("send notification to dingding: %w", err)
|
||||
}
|
||||
|
||||
|
||||
@@ -114,7 +114,7 @@ func (d DiscordNotifier) Notify(ctx context.Context, as ...*types.Alert) (bool,
|
||||
Body: string(body),
|
||||
}
|
||||
|
||||
if err := bus.DispatchCtx(ctx, cmd); err != nil {
|
||||
if err := bus.Dispatch(ctx, cmd); err != nil {
|
||||
d.log.Error("Failed to send notification to Discord", "error", err)
|
||||
return false, err
|
||||
}
|
||||
|
||||
@@ -103,7 +103,7 @@ func (en *EmailNotifier) Notify(ctx context.Context, as ...*types.Alert) (bool,
|
||||
en.log.Debug("failed to template email message", "err", tmplErr.Error())
|
||||
}
|
||||
|
||||
if err := bus.DispatchCtx(ctx, cmd); err != nil {
|
||||
if err := bus.Dispatch(ctx, cmd); err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
|
||||
@@ -128,7 +128,7 @@ func (gcn *GoogleChatNotifier) Notify(ctx context.Context, as ...*types.Alert) (
|
||||
Body: string(body),
|
||||
}
|
||||
|
||||
if err := bus.DispatchCtx(ctx, cmd); err != nil {
|
||||
if err := bus.Dispatch(ctx, cmd); err != nil {
|
||||
gcn.log.Error("Failed to send Google Hangouts Chat alert", "error", err, "webhook", gcn.Name)
|
||||
return false, err
|
||||
}
|
||||
|
||||
@@ -112,7 +112,7 @@ func (kn *KafkaNotifier) Notify(ctx context.Context, as ...*types.Alert) (bool,
|
||||
},
|
||||
}
|
||||
|
||||
if err := bus.DispatchCtx(ctx, cmd); err != nil {
|
||||
if err := bus.Dispatch(ctx, cmd); err != nil {
|
||||
kn.log.Error("Failed to send notification to Kafka", "error", err, "body", string(body))
|
||||
return false, err
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ func (ln *LineNotifier) Notify(ctx context.Context, as ...*types.Alert) (bool, e
|
||||
Body: form.Encode(),
|
||||
}
|
||||
|
||||
if err := bus.DispatchCtx(ctx, cmd); err != nil {
|
||||
if err := bus.Dispatch(ctx, cmd); err != nil {
|
||||
ln.log.Error("Failed to send notification to LINE", "error", err, "body", body)
|
||||
return false, err
|
||||
}
|
||||
|
||||
@@ -120,7 +120,7 @@ func (on *OpsgenieNotifier) Notify(ctx context.Context, as ...*types.Alert) (boo
|
||||
},
|
||||
}
|
||||
|
||||
if err := bus.DispatchCtx(ctx, cmd); err != nil {
|
||||
if err := bus.Dispatch(ctx, cmd); err != nil {
|
||||
return false, fmt.Errorf("send notification to Opsgenie: %w", err)
|
||||
}
|
||||
|
||||
|
||||
@@ -105,7 +105,7 @@ func (pn *PagerdutyNotifier) Notify(ctx context.Context, as ...*types.Alert) (bo
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
}
|
||||
if err := bus.DispatchCtx(ctx, cmd); err != nil {
|
||||
if err := bus.Dispatch(ctx, cmd); err != nil {
|
||||
return false, fmt.Errorf("send notification to Pagerduty: %w", err)
|
||||
}
|
||||
|
||||
|
||||
@@ -110,7 +110,7 @@ func (pn *PushoverNotifier) Notify(ctx context.Context, as ...*types.Alert) (boo
|
||||
Body: uploadBody.String(),
|
||||
}
|
||||
|
||||
if err := bus.DispatchCtx(ctx, cmd); err != nil {
|
||||
if err := bus.Dispatch(ctx, cmd); err != nil {
|
||||
pn.log.Error("Failed to send pushover notification", "error", err, "webhook", pn.Name)
|
||||
return false, err
|
||||
}
|
||||
|
||||
@@ -145,7 +145,7 @@ func (sn *SensuGoNotifier) Notify(ctx context.Context, as ...*types.Alert) (bool
|
||||
"Authorization": fmt.Sprintf("Key %s", sn.APIKey),
|
||||
},
|
||||
}
|
||||
if err := bus.DispatchCtx(ctx, cmd); err != nil {
|
||||
if err := bus.Dispatch(ctx, cmd); err != nil {
|
||||
sn.log.Error("Failed to send Sensu Go event", "error", err, "sensugo", sn.Name)
|
||||
return false, err
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ func (tn *TeamsNotifier) Notify(ctx context.Context, as ...*types.Alert) (bool,
|
||||
}
|
||||
cmd := &models.SendWebhookSync{Url: u, Body: string(b)}
|
||||
|
||||
if err := bus.DispatchCtx(ctx, cmd); err != nil {
|
||||
if err := bus.Dispatch(ctx, cmd); err != nil {
|
||||
return false, errors.Wrap(err, "send notification to Teams")
|
||||
}
|
||||
|
||||
|
||||
@@ -109,7 +109,7 @@ func (tn *TelegramNotifier) Notify(ctx context.Context, as ...*types.Alert) (boo
|
||||
},
|
||||
}
|
||||
|
||||
if err := bus.DispatchCtx(ctx, cmd); err != nil {
|
||||
if err := bus.Dispatch(ctx, cmd); err != nil {
|
||||
tn.log.Error("Failed to send webhook", "error", err, "webhook", tn.Name)
|
||||
return false, err
|
||||
}
|
||||
|
||||
@@ -119,7 +119,7 @@ func (tn *ThreemaNotifier) Notify(ctx context.Context, as ...*types.Alert) (bool
|
||||
"Content-Type": "application/x-www-form-urlencoded",
|
||||
},
|
||||
}
|
||||
if err := bus.DispatchCtx(ctx, cmd); err != nil {
|
||||
if err := bus.Dispatch(ctx, cmd); err != nil {
|
||||
tn.log.Error("Failed to send threema notification", "error", err, "webhook", tn.Name)
|
||||
return false, err
|
||||
}
|
||||
|
||||
@@ -109,7 +109,7 @@ func (vn *VictoropsNotifier) Notify(ctx context.Context, as ...*types.Alert) (bo
|
||||
Body: string(b),
|
||||
}
|
||||
|
||||
if err := bus.DispatchCtx(ctx, cmd); err != nil {
|
||||
if err := bus.Dispatch(ctx, cmd); err != nil {
|
||||
vn.log.Error("Failed to send Victorops notification", "error", err, "webhook", vn.Name)
|
||||
return false, err
|
||||
}
|
||||
|
||||
@@ -118,7 +118,7 @@ func (wn *WebhookNotifier) Notify(ctx context.Context, as ...*types.Alert) (bool
|
||||
HttpMethod: wn.HTTPMethod,
|
||||
}
|
||||
|
||||
if err := bus.DispatchCtx(ctx, cmd); err != nil {
|
||||
if err := bus.Dispatch(ctx, cmd); err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
|
||||
@@ -74,7 +74,7 @@ func (w *WeComNotifier) Notify(ctx context.Context, as ...*types.Alert) (bool, e
|
||||
Body: string(body),
|
||||
}
|
||||
|
||||
if err := bus.DispatchCtx(ctx, cmd); err != nil {
|
||||
if err := bus.Dispatch(ctx, cmd); err != nil {
|
||||
w.log.Error("failed to send WeCom webhook", "error", err, "notification", w.Name)
|
||||
return false, err
|
||||
}
|
||||
|
||||
@@ -170,7 +170,7 @@ func (ns *NotificationService) validateResetPasswordCode(ctx context.Context, qu
|
||||
}
|
||||
|
||||
userQuery := models.GetUserByLoginQuery{LoginOrEmail: login}
|
||||
if err := bus.DispatchCtx(ctx, &userQuery); err != nil {
|
||||
if err := bus.Dispatch(ctx, &userQuery); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -212,7 +212,7 @@ func (ns *NotificationService) signUpStartedHandler(ctx context.Context, evt *ev
|
||||
}
|
||||
|
||||
emailSentCmd := models.UpdateTempUserWithEmailSentCommand{Code: evt.Code}
|
||||
return bus.DispatchCtx(ctx, &emailSentCmd)
|
||||
return bus.Dispatch(ctx, &emailSentCmd)
|
||||
}
|
||||
|
||||
func (ns *NotificationService) signUpCompletedHandler(ctx context.Context, evt *events.SignUpCompleted) error {
|
||||
|
||||
@@ -38,7 +38,7 @@ func (o *Service) GetCurrentOAuthToken(ctx context.Context, user *models.SignedI
|
||||
}
|
||||
|
||||
authInfoQuery := &models.GetAuthInfoQuery{UserId: user.UserId}
|
||||
if err := bus.DispatchCtx(ctx, authInfoQuery); err != nil {
|
||||
if err := bus.Dispatch(ctx, authInfoQuery); err != nil {
|
||||
if errors.Is(err, models.ErrUserNotFound) {
|
||||
// Not necessarily an error. User may be logged in another way.
|
||||
logger.Debug("no OAuth token for user found", "userId", user.UserId, "username", user.Login)
|
||||
@@ -88,7 +88,7 @@ func (o *Service) GetCurrentOAuthToken(ctx context.Context, user *models.SignedI
|
||||
AuthId: authInfoQuery.Result.AuthId,
|
||||
OAuthToken: token,
|
||||
}
|
||||
if err := bus.DispatchCtx(ctx, updateAuthCommand); err != nil {
|
||||
if err := bus.Dispatch(ctx, updateAuthCommand); err != nil {
|
||||
logger.Error("failed to update auth info during token refresh", "userId", user.UserId, "username", user.Login, "error", err)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ func (provider *Provisioner) CleanUpOrphanedDashboards(ctx context.Context) {
|
||||
currentReaders[index] = reader.Cfg.Name
|
||||
}
|
||||
|
||||
if err := bus.DispatchCtx(ctx, &models.DeleteOrphanedProvisionedDashboardsCommand{ReaderNames: currentReaders}); err != nil {
|
||||
if err := bus.Dispatch(ctx, &models.DeleteOrphanedProvisionedDashboardsCommand{ReaderNames: currentReaders}); err != nil {
|
||||
provider.log.Warn("Failed to delete orphaned provisioned dashboards", "err", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -297,7 +297,7 @@ func getOrCreateFolderID(ctx context.Context, cfg *config, service dashboards.Da
|
||||
}
|
||||
|
||||
cmd := &models.GetDashboardQuery{Slug: models.SlugifyTitle(folderName), OrgId: cfg.OrgID}
|
||||
err := bus.DispatchCtx(ctx, cmd)
|
||||
err := bus.Dispatch(ctx, cmd)
|
||||
|
||||
if err != nil && !errors.Is(err, models.ErrDashboardNotFound) {
|
||||
return 0, err
|
||||
|
||||
@@ -45,7 +45,7 @@ func (dc *DatasourceProvisioner) apply(ctx context.Context, cfg *configs) error
|
||||
|
||||
for _, ds := range cfg.Datasources {
|
||||
cmd := &models.GetDataSourceQuery{OrgId: ds.OrgID, Name: ds.Name}
|
||||
err := bus.DispatchCtx(ctx, cmd)
|
||||
err := bus.Dispatch(ctx, cmd)
|
||||
if err != nil && !errors.Is(err, models.ErrDataSourceNotFound) {
|
||||
return err
|
||||
}
|
||||
@@ -53,13 +53,13 @@ func (dc *DatasourceProvisioner) apply(ctx context.Context, cfg *configs) error
|
||||
if errors.Is(err, models.ErrDataSourceNotFound) {
|
||||
insertCmd := createInsertCommand(ds)
|
||||
dc.log.Info("inserting datasource from configuration ", "name", insertCmd.Name, "uid", insertCmd.Uid)
|
||||
if err := bus.DispatchCtx(ctx, insertCmd); err != nil {
|
||||
if err := bus.Dispatch(ctx, insertCmd); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
updateCmd := createUpdateCommand(ds, cmd.Result.Id)
|
||||
dc.log.Debug("updating datasource from configuration", "name", updateCmd.Name, "uid", updateCmd.Uid)
|
||||
if err := bus.DispatchCtx(ctx, updateCmd); err != nil {
|
||||
if err := bus.Dispatch(ctx, updateCmd); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -86,7 +86,7 @@ func (dc *DatasourceProvisioner) applyChanges(ctx context.Context, configPath st
|
||||
func (dc *DatasourceProvisioner) deleteDatasources(ctx context.Context, dsToDelete []*deleteDatasourceConfig) error {
|
||||
for _, ds := range dsToDelete {
|
||||
cmd := &models.DeleteDataSourceCommand{OrgID: ds.OrgID, Name: ds.Name}
|
||||
if err := bus.DispatchCtx(ctx, cmd); err != nil {
|
||||
if err := bus.Dispatch(ctx, cmd); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ func (dc *NotificationProvisioner) deleteNotifications(ctx context.Context, noti
|
||||
|
||||
if notification.OrgID == 0 && notification.OrgName != "" {
|
||||
getOrg := &models.GetOrgByNameQuery{Name: notification.OrgName}
|
||||
if err := bus.DispatchCtx(ctx, getOrg); err != nil {
|
||||
if err := bus.Dispatch(ctx, getOrg); err != nil {
|
||||
return err
|
||||
}
|
||||
notification.OrgID = getOrg.Result.Id
|
||||
@@ -58,13 +58,13 @@ func (dc *NotificationProvisioner) deleteNotifications(ctx context.Context, noti
|
||||
|
||||
getNotification := &models.GetAlertNotificationsWithUidQuery{Uid: notification.UID, OrgId: notification.OrgID}
|
||||
|
||||
if err := bus.DispatchCtx(ctx, getNotification); err != nil {
|
||||
if err := bus.Dispatch(ctx, getNotification); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if getNotification.Result != nil {
|
||||
cmd := &models.DeleteAlertNotificationWithUidCommand{Uid: getNotification.Result.Uid, OrgId: getNotification.OrgId}
|
||||
if err := bus.DispatchCtx(ctx, cmd); err != nil {
|
||||
if err := bus.Dispatch(ctx, cmd); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -77,7 +77,7 @@ func (dc *NotificationProvisioner) mergeNotifications(ctx context.Context, notif
|
||||
for _, notification := range notificationToMerge {
|
||||
if notification.OrgID == 0 && notification.OrgName != "" {
|
||||
getOrg := &models.GetOrgByNameQuery{Name: notification.OrgName}
|
||||
if err := bus.DispatchCtx(ctx, getOrg); err != nil {
|
||||
if err := bus.Dispatch(ctx, getOrg); err != nil {
|
||||
return err
|
||||
}
|
||||
notification.OrgID = getOrg.Result.Id
|
||||
@@ -86,7 +86,7 @@ func (dc *NotificationProvisioner) mergeNotifications(ctx context.Context, notif
|
||||
}
|
||||
|
||||
cmd := &models.GetAlertNotificationsWithUidQuery{OrgId: notification.OrgID, Uid: notification.UID}
|
||||
err := bus.DispatchCtx(ctx, cmd)
|
||||
err := bus.Dispatch(ctx, cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -106,7 +106,7 @@ func (dc *NotificationProvisioner) mergeNotifications(ctx context.Context, notif
|
||||
SendReminder: notification.SendReminder,
|
||||
}
|
||||
|
||||
if err := bus.DispatchCtx(ctx, insertCmd); err != nil {
|
||||
if err := bus.Dispatch(ctx, insertCmd); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
@@ -124,7 +124,7 @@ func (dc *NotificationProvisioner) mergeNotifications(ctx context.Context, notif
|
||||
SendReminder: notification.SendReminder,
|
||||
}
|
||||
|
||||
if err := bus.DispatchCtx(ctx, updateCmd); err != nil {
|
||||
if err := bus.Dispatch(ctx, updateCmd); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ func (ap *PluginProvisioner) apply(ctx context.Context, cfg *pluginsAsConfig) er
|
||||
for _, app := range cfg.Apps {
|
||||
if app.OrgID == 0 && app.OrgName != "" {
|
||||
getOrgQuery := &models.GetOrgByNameQuery{Name: app.OrgName}
|
||||
if err := bus.DispatchCtx(ctx, getOrgQuery); err != nil {
|
||||
if err := bus.Dispatch(ctx, getOrgQuery); err != nil {
|
||||
return err
|
||||
}
|
||||
app.OrgID = getOrgQuery.Result.Id
|
||||
@@ -41,7 +41,7 @@ func (ap *PluginProvisioner) apply(ctx context.Context, cfg *pluginsAsConfig) er
|
||||
}
|
||||
|
||||
query := &models.GetPluginSettingByIdQuery{OrgId: app.OrgID, PluginId: app.PluginID}
|
||||
err := bus.DispatchCtx(ctx, query)
|
||||
err := bus.Dispatch(ctx, query)
|
||||
if err != nil {
|
||||
if !errors.Is(err, models.ErrPluginSettingNotFound) {
|
||||
return err
|
||||
@@ -60,7 +60,7 @@ func (ap *PluginProvisioner) apply(ctx context.Context, cfg *pluginsAsConfig) er
|
||||
SecureJsonData: app.SecureJSONData,
|
||||
PluginVersion: app.PluginVersion,
|
||||
}
|
||||
if err := bus.DispatchCtx(ctx, cmd); err != nil {
|
||||
if err := bus.Dispatch(ctx, cmd); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
|
||||
func CheckOrgExists(ctx context.Context, orgID int64) error {
|
||||
query := models.GetOrgByIdQuery{Id: orgID}
|
||||
if err := bus.DispatchCtx(ctx, &query); err != nil {
|
||||
if err := bus.Dispatch(ctx, &query); err != nil {
|
||||
if errors.Is(err, models.ErrOrgNotFound) {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ func (qs *QuotaService) QuotaReached(c *models.ReqContext, target string) (bool,
|
||||
continue
|
||||
}
|
||||
query := models.GetGlobalQuotaByTargetQuery{Target: scope.Target, UnifiedAlertingEnabled: qs.Cfg.UnifiedAlerting.IsEnabled()}
|
||||
if err := bus.DispatchCtx(c.Req.Context(), &query); err != nil {
|
||||
if err := bus.Dispatch(c.Req.Context(), &query); err != nil {
|
||||
return true, err
|
||||
}
|
||||
if query.Result.Used >= scope.DefaultLimit {
|
||||
@@ -79,7 +79,7 @@ func (qs *QuotaService) QuotaReached(c *models.ReqContext, target string) (bool,
|
||||
Default: scope.DefaultLimit,
|
||||
UnifiedAlertingEnabled: qs.Cfg.UnifiedAlerting.IsEnabled(),
|
||||
}
|
||||
if err := bus.DispatchCtx(c.Req.Context(), &query); err != nil {
|
||||
if err := bus.Dispatch(c.Req.Context(), &query); err != nil {
|
||||
return true, err
|
||||
}
|
||||
if query.Result.Limit < 0 {
|
||||
@@ -97,7 +97,7 @@ func (qs *QuotaService) QuotaReached(c *models.ReqContext, target string) (bool,
|
||||
continue
|
||||
}
|
||||
query := models.GetUserQuotaByTargetQuery{UserId: c.UserId, Target: scope.Target, Default: scope.DefaultLimit, UnifiedAlertingEnabled: qs.Cfg.UnifiedAlerting.IsEnabled()}
|
||||
if err := bus.DispatchCtx(c.Req.Context(), &query); err != nil {
|
||||
if err := bus.Dispatch(c.Req.Context(), &query); err != nil {
|
||||
return true, err
|
||||
}
|
||||
if query.Result.Limit < 0 {
|
||||
|
||||
@@ -84,7 +84,7 @@ func (s *SearchService) searchHandler(ctx context.Context, query *Query) error {
|
||||
dashboardQuery.Sort = sortOpt
|
||||
}
|
||||
|
||||
if err := bus.DispatchCtx(ctx, &dashboardQuery); err != nil {
|
||||
if err := bus.Dispatch(ctx, &dashboardQuery); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -120,7 +120,7 @@ func setStarredDashboards(ctx context.Context, userID int64, hits []*Hit) error
|
||||
UserId: userID,
|
||||
}
|
||||
|
||||
if err := bus.DispatchCtx(ctx, &query); err != nil {
|
||||
if err := bus.Dispatch(ctx, &query); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ func (s *OSSService) SearchUser(c *models.ReqContext) (*models.SearchUsersQuery,
|
||||
}
|
||||
|
||||
query := &models.SearchUsersQuery{Query: searchQuery, Filters: filters, Page: page, Limit: perPage}
|
||||
if err := s.bus.DispatchCtx(c.Req.Context(), query); err != nil {
|
||||
if err := s.bus.Dispatch(c.Req.Context(), query); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ func (ss *SQLStore) DeleteAlertNotificationWithUid(ctx context.Context, cmd *mod
|
||||
Id: existingNotification.Result.Id,
|
||||
OrgId: existingNotification.Result.OrgId,
|
||||
}
|
||||
if err := bus.DispatchCtx(ctx, deleteCommand); err != nil {
|
||||
if err := bus.Dispatch(ctx, deleteCommand); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -454,7 +454,7 @@ func (ss *SQLStore) UpdateAlertNotificationWithUid(ctx context.Context, cmd *mod
|
||||
OrgId: cmd.OrgId,
|
||||
}
|
||||
|
||||
if err := bus.DispatchCtx(ctx, updateNotification); err != nil {
|
||||
if err := bus.Dispatch(ctx, updateNotification); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ func CanAdmin(ctx context.Context, bus bus.Bus, orgId int64, teamId int64, user
|
||||
UserId: user.UserId,
|
||||
}
|
||||
|
||||
if err := bus.DispatchCtx(ctx, &cmd); err != nil {
|
||||
if err := bus.Dispatch(ctx, &cmd); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -246,7 +246,7 @@ func (hs *thumbService) StopCrawler(c *models.ReqContext) response.Response {
|
||||
func (hs *thumbService) getStatus(c *models.ReqContext, uid string, checkSave bool) int {
|
||||
query := models.GetDashboardQuery{Uid: uid, OrgId: c.OrgId}
|
||||
|
||||
if err := bus.DispatchCtx(c.Req.Context(), &query); err != nil {
|
||||
if err := bus.Dispatch(c.Req.Context(), &query); err != nil {
|
||||
return 404 // not found
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user