Skip to content

Commit

Permalink
patch: bad legacy event type
Browse files Browse the repository at this point in the history
  • Loading branch information
denopink committed Mar 5, 2024
1 parent 35b5e7a commit cdb0b7f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
4 changes: 2 additions & 2 deletions deviceStatus.go
Expand Up @@ -65,7 +65,7 @@ func newOnlineMessage(source string, d device.Interface) (string, *wrp.Message)
}
updateTimestampMetadata(m, t)

return eventType, m
return m.FindEventStringSubMatch(), m
}

func offlinePayload(t time.Time, d device.Interface) []byte {
Expand Down Expand Up @@ -108,7 +108,7 @@ func newOfflineMessage(source string, d device.Interface) (string, *wrp.Message)
}
updateTimestampMetadata(m, t)

return eventType, m
return m.FindEventStringSubMatch(), m
}

func updateTimestampMetadata(m *wrp.Message, t time.Time) {
Expand Down
7 changes: 4 additions & 3 deletions eventDispatcher.go
Expand Up @@ -138,8 +138,9 @@ func (d *eventDispatcher) OnDeviceEvent(event *device.Event) {
d.logger.Error("Error dispatching event", zap.Any("eventType", eventType), zap.Any("destination", destination), zap.Error(err))
}
} else if strings.HasPrefix(destination, DNSPrefix) {
eventType = event.Type.String()
unfilteredURL := destination[len(DNSPrefix):]
url, err = d.dispatchTo(unfilteredURL, contentType, event.Contents)
url, err = d.dispatchTo(unfilteredURL, contentType, event.Contents, eventType)
if err != nil {
d.logger.Error("Error dispatching to endpoint", zap.Any("destination", destination), zap.Error(err))
}
Expand Down Expand Up @@ -261,7 +262,7 @@ func (d *eventDispatcher) encodeAndDispatchEvent(eventType string, format wrp.Fo
return url, nil
}

func (d *eventDispatcher) dispatchTo(unfiltered string, contentType string, contents []byte) (string, error) {
func (d *eventDispatcher) dispatchTo(unfiltered string, contentType string, contents []byte, eventType string) (string, error) {
var (
err error
url = unfiltered
Expand All @@ -278,7 +279,7 @@ func (d *eventDispatcher) dispatchTo(unfiltered string, contentType string, cont
}

return request.URL.String(), d.send(
context.WithValue(context.Background(), eventTypeContextKey{}, DNSPrefix),
context.WithValue(context.Background(), eventTypeContextKey{}, eventType),
request,
)
}
Expand Down

0 comments on commit cdb0b7f

Please sign in to comment.