@@ -112,36 +112,46 @@ func isActivityAndActivityOnly(updatedFields []string) bool {
112
112
return hasActivity
113
113
}
114
114
115
+ // deviceDataIdentifiers are common to DosingDecision and Glucose.
116
+ //
117
+ // They facilitate queries of the latest data for alerts evaluation.
118
+ type deviceDataIdentifiers struct {
119
+ UploadID string `json:"uploadId,omitempty" bson:"uploadId,omitempty"`
120
+ UserID string `json:"-" bson:"_userId,omitempty"`
121
+ }
122
+
115
123
func (c * Consumer ) consumeDeviceData (ctx context.Context ,
116
124
session sarama.ConsumerGroupSession , msg * sarama.ConsumerMessage ) error {
117
125
118
- datum := & Glucose {}
119
- if _ , err := unmarshalMessageValue (msg .Value , datum ); err != nil {
120
- return err
121
- }
122
126
lgr := c .logger (ctx )
123
- lgr .WithField ("data" , datum ).Info ("consuming a device data message" )
124
127
125
- if datum .UserID == nil {
126
- return errors .New ("Unable to retrieve alerts configs: userID is nil" )
128
+ id := & deviceDataIdentifiers {}
129
+ if _ , err := unmarshalMessageValue (msg .Value , id ); err != nil {
130
+ return errors .Wrap (err , "Unable to unmarshal device data message" )
131
+ }
132
+
133
+ lgr .WithField ("identifiers" , id ).Info ("consuming a device data message" )
134
+
135
+ if id .UserID == "" {
136
+ return errors .New ("Unable to retrieve alerts configs: userID is empty" )
127
137
}
128
- if datum .UploadID == nil {
129
- return errors .New ("Unable to retrieve alerts configs: DataSetID is nil " )
138
+ if id .UploadID == "" {
139
+ return errors .New ("Unable to retrieve alerts configs: DataSetID is empty " )
130
140
}
131
- ctx = log .NewContextWithLogger (ctx , lgr .WithField ("followedUserID" , * datum .UserID ))
141
+ ctx = log .NewContextWithLogger (ctx , lgr .WithField ("followedUserID" , id .UserID ))
132
142
lastComm := alerts.LastCommunication {
133
- UserID : * datum .UserID ,
143
+ UserID : id .UserID ,
134
144
LastReceivedDeviceData : time .Now (),
135
- DataSetID : * datum .UploadID ,
145
+ DataSetID : id .UploadID ,
136
146
}
137
147
err := c .LastCommunications .RecordReceivedDeviceData (ctx , lastComm )
138
148
if err != nil {
139
149
lgr .WithError (err ).Info ("Unable to record device data received" )
140
150
}
141
- notes , err := c .Evaluator .EvaluateData (ctx , * datum .UserID , * datum .UploadID )
151
+ notes , err := c .Evaluator .EvaluateData (ctx , id .UserID , id .UploadID )
142
152
if err != nil {
143
153
format := "Unable to evalaute device data triggered event for user %s"
144
- return errors .Wrapf (err , format , * datum .UserID )
154
+ return errors .Wrapf (err , format , id .UserID )
145
155
}
146
156
for idx , note := range notes {
147
157
lgr .WithField ("idx" , idx ).WithField ("note" , note ).Debug ("notes" )
0 commit comments