appview/notify: pass logger with mergedLogger #693

merged
opened by boltless.me targeting master from boltless.me/core: feat/search
Changed files
+14 -9
appview
indexer
notify
state
+3 -3
appview/indexer/notifier.go
··· 11 var _ notify.Notifier = &Indexer{} 12 13 func (ix *Indexer) NewIssue(ctx context.Context, issue *models.Issue) { 14 - l := log.FromContext(ctx).With("notifier", "indexer.NewIssue", "issue", issue) 15 l.Debug("indexing new issue") 16 err := ix.Issues.Index(ctx, *issue) 17 if err != nil { ··· 20 } 21 22 func (ix *Indexer) NewIssueClosed(ctx context.Context, issue *models.Issue) { 23 - l := log.FromContext(ctx).With("notifier", "indexer.NewIssueClosed", "issue", issue) 24 l.Debug("updating an issue") 25 err := ix.Issues.Index(ctx, *issue) 26 if err != nil { ··· 29 } 30 31 func (ix *Indexer) DeleteIssue(ctx context.Context, issue *models.Issue) { 32 - l := log.FromContext(ctx).With("notifier", "indexer.DeleteIssue", "issue", issue) 33 l.Debug("deleting an issue") 34 err := ix.Issues.Delete(ctx, issue.Id) 35 if err != nil {
··· 11 var _ notify.Notifier = &Indexer{} 12 13 func (ix *Indexer) NewIssue(ctx context.Context, issue *models.Issue) { 14 + l := log.FromContext(ctx).With("notifier", "indexer", "issue", issue) 15 l.Debug("indexing new issue") 16 err := ix.Issues.Index(ctx, *issue) 17 if err != nil { ··· 20 } 21 22 func (ix *Indexer) NewIssueClosed(ctx context.Context, issue *models.Issue) { 23 + l := log.FromContext(ctx).With("notifier", "indexer", "issue", issue) 24 l.Debug("updating an issue") 25 err := ix.Issues.Index(ctx, *issue) 26 if err != nil { ··· 29 } 30 31 func (ix *Indexer) DeleteIssue(ctx context.Context, issue *models.Issue) { 32 + l := log.FromContext(ctx).With("notifier", "indexer", "issue", issue) 33 l.Debug("deleting an issue") 34 err := ix.Issues.Delete(ctx, issue.Id) 35 if err != nil {
+10 -5
appview/notify/merged_notifier.go
··· 2 3 import ( 4 "context" 5 "reflect" 6 "sync" 7 8 "tangled.org/core/appview/models" 9 ) 10 11 type mergedNotifier struct { 12 notifiers []Notifier 13 } 14 15 - func NewMergedNotifier(notifiers ...Notifier) Notifier { 16 - return &mergedNotifier{notifiers} 17 } 18 19 var _ Notifier = &mergedNotifier{} 20 21 // fanout calls the same method on all notifiers concurrently 22 - func (m *mergedNotifier) fanout(method string, args ...any) { 23 var wg sync.WaitGroup 24 for _, n := range m.notifiers { 25 wg.Add(1) 26 go func(notifier Notifier) { 27 defer wg.Done() 28 v := reflect.ValueOf(notifier).MethodByName(method) 29 - in := make([]reflect.Value, len(args)) 30 for i, arg := range args { 31 - in[i] = reflect.ValueOf(arg) 32 } 33 v.Call(in) 34 }(n)
··· 2 3 import ( 4 "context" 5 + "log/slog" 6 "reflect" 7 "sync" 8 9 "tangled.org/core/appview/models" 10 + "tangled.org/core/log" 11 ) 12 13 type mergedNotifier struct { 14 notifiers []Notifier 15 + logger *slog.Logger 16 } 17 18 + func NewMergedNotifier(notifiers []Notifier, logger *slog.Logger) Notifier { 19 + return &mergedNotifier{notifiers, logger} 20 } 21 22 var _ Notifier = &mergedNotifier{} 23 24 // fanout calls the same method on all notifiers concurrently 25 + func (m *mergedNotifier) fanout(method string, ctx context.Context, args ...any) { 26 + ctx = log.IntoContext(ctx, m.logger.With("method", method)) 27 var wg sync.WaitGroup 28 for _, n := range m.notifiers { 29 wg.Add(1) 30 go func(notifier Notifier) { 31 defer wg.Done() 32 v := reflect.ValueOf(notifier).MethodByName(method) 33 + in := make([]reflect.Value, len(args)+1) 34 + in[0] = reflect.ValueOf(ctx) 35 for i, arg := range args { 36 + in[i+1] = reflect.ValueOf(arg) 37 } 38 v.Call(in) 39 }(n)
+1 -1
appview/state/state.go
··· 168 notifiers = append(notifiers, phnotify.NewPosthogNotifier(posthog)) 169 } 170 notifiers = append(notifiers, indexer) 171 - notifier := notify.NewMergedNotifier(notifiers...) 172 173 state := &State{ 174 d,
··· 168 notifiers = append(notifiers, phnotify.NewPosthogNotifier(posthog)) 169 } 170 notifiers = append(notifiers, indexer) 171 + notifier := notify.NewMergedNotifier(notifiers, tlog.SubLogger(logger, "notify")) 172 173 state := &State{ 174 d,