mirror of
https://github.com/foomo/sesamy-go.git
synced 2025-10-16 12:35:43 +00:00
feat: use request context
This commit is contained in:
parent
d88146a2e9
commit
3a414aba79
@ -131,12 +131,12 @@ func (s *Subscriber) handle(l *zap.Logger, r *http.Request, payload *gtag.Payloa
|
||||
|
||||
msg := message.NewMessage(s.uuidFunc(), data)
|
||||
l = l.With(zap.String("message_id", msg.UUID))
|
||||
msg.SetContext(context.WithoutCancel(r.Context()))
|
||||
|
||||
if payload.EventName != nil {
|
||||
msg.Metadata.Set(MetadataEventName, gtag.Get(payload.EventName).String())
|
||||
}
|
||||
|
||||
// TODO filter headers?
|
||||
for name, headers := range r.Header {
|
||||
msg.Metadata.Set(name, strings.Join(headers, ","))
|
||||
}
|
||||
@ -145,11 +145,6 @@ func (s *Subscriber) handle(l *zap.Logger, r *http.Request, payload *gtag.Payloa
|
||||
l = l.With(zap.String(k, v))
|
||||
}
|
||||
|
||||
// TODO different context?
|
||||
ctx, cancelCtx := context.WithCancel(r.Context())
|
||||
msg.SetContext(ctx)
|
||||
defer cancelCtx()
|
||||
|
||||
// send message
|
||||
s.messages <- msg
|
||||
|
||||
@ -162,7 +157,7 @@ func (s *Subscriber) handle(l *zap.Logger, r *http.Request, payload *gtag.Payloa
|
||||
l.Debug("message nacked")
|
||||
return ErrMessageNacked
|
||||
case <-r.Context().Done():
|
||||
l.Debug("message cancled")
|
||||
l.Debug("message canceled")
|
||||
return ErrContextCanceled
|
||||
}
|
||||
}
|
||||
|
||||
@ -110,29 +110,16 @@ func (s *Subscriber) handle(l *zap.Logger, r *http.Request, payload *mpv2.Payloa
|
||||
|
||||
msg := message.NewMessage(s.uuidFunc(), jsonPayload)
|
||||
l = l.With(zap.String("message_id", msg.UUID))
|
||||
msg.SetContext(context.WithoutCancel(r.Context()))
|
||||
|
||||
// TODO filter headers?
|
||||
for name, headers := range r.Header {
|
||||
msg.Metadata.Set(name, strings.Join(headers, ","))
|
||||
}
|
||||
|
||||
// if cookies := r.Cookies(); len(cookies) > 0 {
|
||||
// values := make([]string, len(cookies))
|
||||
// for i, cookie := range r.Cookies() {
|
||||
// values[i] = cookie.String()
|
||||
// }
|
||||
// msg.Metadata.Set("Cookie", strings.Join(values, "; "))
|
||||
// }
|
||||
|
||||
for k, v := range msg.Metadata {
|
||||
l = l.With(zap.String(k, v))
|
||||
}
|
||||
|
||||
// TODO different context?
|
||||
ctx, cancelCtx := context.WithCancel(r.Context())
|
||||
msg.SetContext(ctx)
|
||||
defer cancelCtx()
|
||||
|
||||
// send message
|
||||
s.messages <- msg
|
||||
|
||||
@ -145,7 +132,7 @@ func (s *Subscriber) handle(l *zap.Logger, r *http.Request, payload *mpv2.Payloa
|
||||
l.Debug("message nacked")
|
||||
return ErrMessageNacked
|
||||
case <-r.Context().Done():
|
||||
l.Debug("message cancled")
|
||||
l.Debug("message canceled")
|
||||
return ErrContextCanceled
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user