Skip to content

Commit 96c4062

Browse files
committed
fixme helpers
1 parent 2fc383e commit 96c4062

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

coderd/notifications/manager.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ type Manager struct {
4646
notifier *notifier
4747
handlers map[database.NotificationMethod]Handler
4848
method database.NotificationMethod
49+
helpers template.FuncMap
4950

5051
metrics *Metrics
5152

@@ -108,6 +109,7 @@ func NewManager(cfg codersdk.NotificationsConfig, store Store, helpers template.
108109
done: make(chan any),
109110

110111
handlers: defaultHandlers(cfg, helpers, log),
112+
helpers: helpers,
111113

112114
clock: quartz.NewReal(),
113115
}
@@ -169,7 +171,7 @@ func (m *Manager) loop(ctx context.Context) error {
169171
var eg errgroup.Group
170172

171173
// Create a notifier to run concurrently, which will handle dequeueing and dispatching notifications.
172-
m.notifier = newNotifier(m.cfg, uuid.New(), m.log, m.store, m.handlers, m.metrics, m.clock)
174+
m.notifier = newNotifier(m.cfg, uuid.New(), m.log, m.store, m.handlers, m.helpers, m.metrics, m.clock)
173175
eg.Go(func() error {
174176
return m.notifier.run(ctx, m.success, m.failure)
175177
})

coderd/notifications/notifier.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"encoding/json"
66
"sync"
7+
"text/template"
78

89
"github.com/google/uuid"
910
"golang.org/x/sync/errgroup"
@@ -36,13 +37,14 @@ type notifier struct {
3637

3738
handlers map[database.NotificationMethod]Handler
3839
metrics *Metrics
40+
helpers template.FuncMap
3941

4042
// clock is for testing
4143
clock quartz.Clock
4244
}
4345

4446
func newNotifier(cfg codersdk.NotificationsConfig, id uuid.UUID, log slog.Logger, db Store,
45-
hr map[database.NotificationMethod]Handler, metrics *Metrics, clock quartz.Clock,
47+
hr map[database.NotificationMethod]Handler, helpers template.FuncMap, metrics *Metrics, clock quartz.Clock,
4648
) *notifier {
4749
tick := clock.NewTicker(cfg.FetchInterval.Value(), "notifier", "fetchInterval")
4850
return &notifier{
@@ -54,6 +56,7 @@ func newNotifier(cfg codersdk.NotificationsConfig, id uuid.UUID, log slog.Logger
5456
tick: tick,
5557
store: db,
5658
handlers: hr,
59+
helpers: helpers,
5760
metrics: metrics,
5861
clock: clock,
5962
}
@@ -221,10 +224,10 @@ func (n *notifier) prepare(ctx context.Context, msg database.AcquireNotification
221224
}
222225

223226
var title, body string
224-
if title, err = render.GoTemplate(msg.TitleTemplate, payload, nil); err != nil { // FIXME helpers
227+
if title, err = render.GoTemplate(msg.TitleTemplate, payload, n.helpers); err != nil {
225228
return nil, xerrors.Errorf("render title: %w", err)
226229
}
227-
if body, err = render.GoTemplate(msg.BodyTemplate, payload, nil); err != nil { // FIXME helpers
230+
if body, err = render.GoTemplate(msg.BodyTemplate, payload, n.helpers); err != nil {
228231
return nil, xerrors.Errorf("render body: %w", err)
229232
}
230233

0 commit comments

Comments
 (0)