Skip to content

Commit 32b9599

Browse files
committed
Clean up logging and improve comments
1 parent 0a9631d commit 32b9599

3 files changed

Lines changed: 15 additions & 29 deletions

File tree

data/work/postprocess/enqueue.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
mapset "github.com/deckarep/golang-set/v2"
99

1010
"github.com/tidepool-org/platform/errors"
11-
"github.com/tidepool-org/platform/log"
1211
"github.com/tidepool-org/platform/metadata"
1312
"github.com/tidepool-org/platform/pointer"
1413
userWork "github.com/tidepool-org/platform/user/work"
@@ -17,8 +16,8 @@ import (
1716

1817
// Enqueue creates a work item to signal a change to the data of a user to trigger the postprocessor.
1918
// Work is created for every change reported, rather than merged into the work already pending for the user,
20-
// so that reporting a change is a single insert when data is uploaded. The work pending for a user is instead
21-
// merged when it is processed.
19+
// so that reporting a change is a single insert when data is uploaded. If there are multiple pending work items
20+
// for the same user, they are merged during processing.
2221
func Enqueue(ctx context.Context, workClient work.Client, userID string, reasons ...string) error {
2322
if ctx == nil {
2423
return errors.New("context is missing")
@@ -42,11 +41,6 @@ func Enqueue(ctx context.Context, workClient work.Client, userID string, reasons
4241
return errors.Wrap(err, "unable to create work")
4342
}
4443

45-
log.LoggerFromContext(ctx).WithFields(log.Fields{
46-
"userId": userID,
47-
"reasons": reasons,
48-
"processingAvailableTime": create.ProcessingAvailableTime,
49-
}).Debug("created work")
5044
return nil
5145
}
5246

data/work/postprocess/processor.go

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func (p *Processor) Process(ctx context.Context, wrk *work.Work, processingUpdat
7070
p.absorbPending,
7171
p.updateSummaries,
7272
p.updateClinicSummaries,
73-
p.triggerElectronicHealthRecordSync,
73+
p.triggerEHRSync,
7474
).Process(p.Delete)
7575
}
7676

@@ -167,7 +167,9 @@ func (p *Processor) updateSummaries() *work.ProcessResult {
167167
p.summariesUpdate, err = p.UpdateSummaries(p.Context(), *p.User().UserID)
168168

169169
// The changes made are recorded in the metadata before they are synced to the clinic service,
170-
// so that a failure between the two retries the update
170+
// so that a failure between the two retries the update. They are recorded even when the
171+
// calculation fails partway (a partial update is returned alongside the error), riding along
172+
// on the failing update so the retry still reports them
171173
changed := p.Metadata().recordSummariesUpdate(p.summariesUpdate)
172174
if err != nil {
173175
return p.Failing(err)
@@ -197,11 +199,6 @@ func (p *Processor) updateClinicSummaries() *work.ProcessResult {
197199
return p.Failing(errors.Wrap(err, "unable to delete patient summary"))
198200
}
199201
}
200-
if len(workMetadata.PendingSummaryDeletes) > 0 {
201-
log.LoggerFromContext(p.Context()).WithFields(log.Fields{
202-
"deleted": workMetadata.PendingSummaryDeletes,
203-
}).Debug("deleted clinic service summaries")
204-
}
205202

206203
var cgm *summaryTypes.CGMSummary
207204
var bgm *summaryTypes.BGMSummary
@@ -215,9 +212,6 @@ func (p *Processor) updateClinicSummaries() *work.ProcessResult {
215212
if err := p.ClinicsClient.UpdatePatientSummary(p.Context(), *p.User().UserID, clinics.NewPatientSummary(cgm, bgm)); err != nil {
216213
return p.Failing(errors.Wrap(err, "unable to update patient summary"))
217214
}
218-
log.LoggerFromContext(p.Context()).WithFields(log.Fields{
219-
"updated": workMetadata.PendingSummaryUpdates,
220-
}).Debug("updated clinic service summaries")
221215
}
222216

223217
log.LoggerFromContext(p.Context()).WithFields(log.Fields{
@@ -228,9 +222,8 @@ func (p *Processor) updateClinicSummaries() *work.ProcessResult {
228222
return nil
229223
}
230224

231-
// triggerElectronicHealthRecordSync reports the data of the user to any electronic health record it
232-
// is shared with. Repeating the request reports the same data again, not twice, so retries are safe.
233-
func (p *Processor) triggerElectronicHealthRecordSync() *work.ProcessResult {
225+
// triggerEHRSync triggers report and flowsheet upload for patients with active subscriptions
226+
func (p *Processor) triggerEHRSync() *work.ProcessResult {
234227
if !TriggersEHRSync(p.Metadata().Reasons) {
235228
return nil
236229
}
@@ -239,8 +232,6 @@ func (p *Processor) triggerElectronicHealthRecordSync() *work.ProcessResult {
239232
return p.Failing(errors.Wrap(err, "unable to trigger EHR sync"))
240233
}
241234

242-
log.LoggerFromContext(p.Context()).Info("triggerred EHR sync")
243-
244235
return nil
245236
}
246237

work/store/structured/mongo/mongo.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,13 @@ func (s *Store) Poll(ctx context.Context, poll *work.Poll) ([]*work.Work, error)
174174
// Group all documents by serial id
175175
pipeline = append(pipeline, bson.M{"$group": bson.M{"_id": "$serialId", "documents": bson.M{"$push": "$$ROOT"}}})
176176

177-
// Match any without a serial id or any serial id group that contains no member in state
178-
// processing nor in state failing with retry time in future ($elemMatch binds both failing
179-
// conditions to the same member). Matching the whole group rather than its head is slightly
180-
// conservative: a group is also excluded when a failing member with a future retry sorts after
181-
// an otherwise eligible head. With uniform priority the failing member sorts first anyway;
182-
// where priorities differ, correctness wins over throughput.
177+
// Match documents without a serial id, and serial id groups with no member processing or
178+
// failing with a future retry time ($elemMatch binds both failing conditions to the same
179+
// member). The whole group is checked, not just its head, because the sort is by priority
180+
// first: a lower-priority processing or failing member can sort behind an eligible sibling,
181+
// and a head-only check would dispatch that sibling — running two members of a serial group
182+
// at once or retrying out of order. Blocking the group whenever such a member exists is
183+
// slightly conservative, but keeps the serial guarantees unconditional.
183184
pipeline = append(pipeline, bson.M{"$match": bson.M{"$or": bson.A{
184185
bson.M{"_id": bson.M{"$exists": false}},
185186
bson.M{"$nor": bson.A{

0 commit comments

Comments
 (0)