Skip to content

Commit b33531a

Browse files
committed
deserialize CPA kafka deviceData messages into a types.Blood
Previously a glucose.Glucose was used, which was fine in that we only look at the UserID and UploadID fields, but there are other incompatible fields that can "spoil" the deserialization. BACK-2559
1 parent 452934e commit b33531a

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

data/events/alerts.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111

1212
"github.com/tidepool-org/platform/alerts"
1313
"github.com/tidepool-org/platform/auth"
14+
"github.com/tidepool-org/platform/data/types"
1415
"github.com/tidepool-org/platform/data/types/blood/glucose"
1516
"github.com/tidepool-org/platform/data/types/dosingdecision"
1617
"github.com/tidepool-org/platform/devicetokens"
@@ -115,13 +116,16 @@ func isActivityAndActivityOnly(updatedFields []string) bool {
115116
func (c *Consumer) consumeDeviceData(ctx context.Context,
116117
session sarama.ConsumerGroupSession, msg *sarama.ConsumerMessage) error {
117118

118-
datum := &Glucose{}
119+
lgr := c.logger(ctx)
120+
lgr.Debug("consuming device data message")
121+
122+
// The actual type should be either a glucose.Glucose or a
123+
// dosingdecision.DosingDecision, but they both use types.Base, and that's where the
124+
// only fields we need are defined.
125+
datum := &types.Base{}
119126
if _, err := unmarshalMessageValue(msg.Value, datum); err != nil {
120127
return err
121128
}
122-
lgr := c.logger(ctx)
123-
lgr.WithField("data", datum).Info("consuming a device data message")
124-
125129
if datum.UserID == nil {
126130
return errors.New("Unable to retrieve alerts configs: userID is nil")
127131
}
@@ -150,7 +154,7 @@ func (c *Consumer) consumeDeviceData(ctx context.Context,
150154
c.pushNotifications(ctx, notes)
151155

152156
session.MarkMessage(msg, "")
153-
lgr.WithField("message", msg).Debug("marked")
157+
lgr.WithField("msg", msg).Debug("marked")
154158
return nil
155159
}
156160

0 commit comments

Comments
 (0)