Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions coderd/notifications/fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,15 @@ import (
"text/template"

"golang.org/x/xerrors"

"cdr.dev/slog"
)

func (n *notifier) fetchHelpers(ctx context.Context) (map[string]any, error) {
appName, err := n.fetchAppName(ctx)
if err != nil {
n.log.Error(ctx, "failed to fetch app name", slog.Error(err))
return nil, xerrors.Errorf("fetch app name: %w", err)
}
logoURL, err := n.fetchLogoURL(ctx)
if err != nil {
n.log.Error(ctx, "failed to fetch logo URL", slog.Error(err))
return nil, xerrors.Errorf("fetch logo URL: %w", err)
}

Expand Down
28 changes: 24 additions & 4 deletions coderd/notifications/notifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package notifications
import (
"context"
"encoding/json"
"fmt"
"sync"
"text/template"

Expand All @@ -27,7 +28,22 @@ const (
notificationsDefaultAppName = "Coder"
)

var errDecorateHelpersFailed = xerrors.New("failed to decorate helpers")
type decorateHelpersError struct {
inner error
}

func (e decorateHelpersError) Error() string {
return fmt.Sprintf("failed to decorate helpers: %s", e.inner.Error())
}

func (e decorateHelpersError) Unwrap() error {
return e.inner
}

func (decorateHelpersError) Is(other error) bool {
_, ok := other.(decorateHelpersError)
return ok
}

// notifier is a consumer of the notifications_messages queue. It dequeues messages from that table and processes them
// through a pipeline of fetch -> prepare -> render -> acquire handler -> deliver.
Expand Down Expand Up @@ -164,8 +180,12 @@ func (n *notifier) process(ctx context.Context, success chan<- dispatchResult, f
// A message failing to be prepared correctly should not affect other messages.
deliverFn, err := n.prepare(ctx, msg)
if err != nil {
n.log.Warn(ctx, "dispatcher construction failed", slog.F("msg_id", msg.ID), slog.Error(err))
failure <- n.newFailedDispatch(msg, err, xerrors.Is(err, errDecorateHelpersFailed))
if database.IsQueryCanceledError(err) {
n.log.Debug(ctx, "dispatcher construction canceled", slog.F("msg_id", msg.ID), slog.Error(err))
} else {
n.log.Error(ctx, "dispatcher construction failed", slog.F("msg_id", msg.ID), slog.Error(err))
}
failure <- n.newFailedDispatch(msg, err, xerrors.Is(err, decorateHelpersError{}))
n.metrics.PendingUpdates.Set(float64(len(success) + len(failure)))
continue
}
Expand Down Expand Up @@ -226,7 +246,7 @@ func (n *notifier) prepare(ctx context.Context, msg database.AcquireNotification

helpers, err := n.fetchHelpers(ctx)
if err != nil {
return nil, errDecorateHelpersFailed
return nil, decorateHelpersError{err}
}

var title, body string
Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy