Skip to content

Commit bce0faa

Browse files
committed
Update logging levels and content
1 parent 2c72e00 commit bce0faa

3 files changed

Lines changed: 19 additions & 31 deletions

File tree

packages/nhsNotifyLambda/src/nhsNotifyLambda.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ async function processBatch(
2828
routingId: string
2929
): Promise<void> {
3030
if (messages.length === 0) {
31-
console.log("No messages to process")
3231
logger.info("No messages to process")
3332
return
3433
}
@@ -57,8 +56,10 @@ async function processBatch(
5756
}
5857

5958
if (processed.length) {
60-
await addPrescriptionMessagesToNotificationStateStore(logger, processed)
61-
await removeSQSMessages(logger, processed)
59+
await Promise.all([
60+
addPrescriptionMessagesToNotificationStateStore(logger, processed),
61+
removeSQSMessages(logger, processed)
62+
])
6263
}
6364
}
6465

@@ -87,7 +88,6 @@ async function drainAndProcess(routingId: string): Promise<void> {
8788
while (!empty) {
8889
const {messages, isEmpty} = await drainQueue(logger, 100)
8990
empty = isEmpty
90-
console.log(messages)
9191
await processBatch(messages, routingId)
9292
}
9393
}
@@ -106,9 +106,9 @@ export const lambdaHandler = async (
106106
throw new Error("No Routing Plan ID found")
107107
}
108108

109-
logger.info("NHS Notify lambda triggered by scheduler", {event})
110-
logger.info("Routing Plan ID:", {routingId})
109+
logger.info("NHS Notify lambda triggered by scheduler", {event, routingId})
111110

111+
// Done sequentially so that the queue report is accurate.
112112
await reportQueueStatus(logger)
113113
await drainAndProcess(routingId)
114114
}

packages/nhsNotifyLambda/src/utils.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -357,14 +357,19 @@ export async function checkCooldownForUpdate(
357357
TableName: dynamoTable,
358358
Key: {
359359
NHSNumber: update.PatientNHSNumber,
360-
ODSCode: update.PharmacyODSCode
360+
ODSCode: update.PharmacyODSCode,
361+
requestID: update.RequestID
361362
}
362363
})
363364
const {Item} = await docClient.send(getCmd)
364365

365366
// If no previous record, we're okay to send a notification
366367
if (!Item?.LastNotificationRequestTimestamp) {
367-
logger.info("No previous notification state found. Notification allowed.")
368+
logger.debug("No previous notification state found. Notification allowed.", {
369+
NHSNumber: update.PatientNHSNumber,
370+
ODSCode: update.PharmacyODSCode,
371+
requestID: update.RequestID
372+
})
368373
return true
369374
}
370375

@@ -374,19 +379,21 @@ export async function checkCooldownForUpdate(
374379
const secondsSince = Math.floor((nowTs - lastTs) / 1000)
375380

376381
if (secondsSince > cooldownPeriod) {
377-
logger.info("Cooldown period has passed. Notification allowed.", {
382+
logger.debug("Cooldown period has passed. Notification allowed.", {
378383
NHSNumber: update.PatientNHSNumber,
379384
ODSCode: update.PharmacyODSCode,
380385
cooldownPeriod,
381-
secondsSince
386+
secondsSince,
387+
requestID: update.RequestID
382388
})
383389
return true
384390
} else {
385-
logger.info("Within cooldown period. Notification suppressed.", {
391+
logger.debug("Within cooldown period. Notification suppressed.", {
386392
NHSNumber: update.PatientNHSNumber,
387393
ODSCode: update.PharmacyODSCode,
388394
cooldownPeriod,
389-
secondsSince
395+
secondsSince,
396+
requestID: update.RequestID
390397
})
391398
return false
392399
}

packages/nhsNotifyLambda/tests/testUtils.test.ts

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -377,9 +377,6 @@ describe("NHS notify lambda helper functions", () => {
377377
const result = await checkCooldownForUpdate(logger, update, 900)
378378

379379
expect(sendSpy).toHaveBeenCalledWith(expect.any(GetCommand))
380-
expect(infoSpy).toHaveBeenCalledWith(
381-
"No previous notification state found. Notification allowed."
382-
)
383380
expect(result).toBe(true)
384381
})
385382

@@ -392,10 +389,6 @@ describe("NHS notify lambda helper functions", () => {
392389
const update = constructPSUDataItemMessage().PSUDataItem
393390
const result = await checkCooldownForUpdate(logger, update, 900)
394391

395-
expect(infoSpy).toHaveBeenCalledWith(
396-
"Cooldown period has passed. Notification allowed.",
397-
expect.objectContaining({secondsSince: expect.any(Number)})
398-
)
399392
expect(result).toBe(true)
400393
})
401394

@@ -408,10 +401,6 @@ describe("NHS notify lambda helper functions", () => {
408401
const update = constructPSUDataItemMessage().PSUDataItem
409402
const result = await checkCooldownForUpdate(logger, update, 900)
410403

411-
expect(infoSpy).toHaveBeenCalledWith(
412-
"Within cooldown period. Notification suppressed.",
413-
expect.objectContaining({secondsSince: expect.any(Number)})
414-
)
415404
expect(result).toBe(false)
416405
})
417406

@@ -425,10 +414,6 @@ describe("NHS notify lambda helper functions", () => {
425414
const update = constructPSUDataItemMessage().PSUDataItem
426415
const result = await checkCooldownForUpdate(logger, update, 60)
427416

428-
expect(infoSpy).toHaveBeenCalledWith(
429-
"Within cooldown period. Notification suppressed.",
430-
expect.objectContaining({secondsSince: expect.any(Number)})
431-
)
432417
expect(result).toBe(false)
433418
})
434419

@@ -438,10 +423,6 @@ describe("NHS notify lambda helper functions", () => {
438423

439424
const update = constructPSUDataItemMessage().PSUDataItem
440425
await expect(checkCooldownForUpdate(logger, update)).rejects.toThrow("DDB failure")
441-
expect(errorSpy).toHaveBeenCalledWith(
442-
"Error checking cooldown state",
443-
expect.objectContaining({error: awsErr})
444-
)
445426
})
446427

447428
it("does nothing when passed an empty array", async () => {

0 commit comments

Comments
 (0)