Skip to content

Commit cf7ce9f

Browse files
debug logging
1 parent 7ee04fa commit cf7ce9f

3 files changed

Lines changed: 28 additions & 11 deletions

File tree

lambdas/supplier-allocator/src/handler/allocate-handler.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
updateSupplierAllocation,
2929
} from "../services/supplier-quotas";
3030
import { Deps } from "../config/deps";
31+
import { de } from "zod/v4/locales";
3132

3233
type SupplierSpec = {
3334
supplierId: string;
@@ -137,19 +138,11 @@ async function getSupplierFromConfig(
137138
suppliersForPack.some((supplier) => supplier.id === alloc.supplier),
138139
);
139140

140-
console.log("Supplier allocations for pack", {
141-
supplierAllocationsForPack,
142-
});
143-
144141
supplierFactors = await calculateSupplierAllocatedFactor(
145142
supplierAllocationsForPack,
146143
deps,
147144
);
148145

149-
console.log("Supplier factors calculated for allocation", {
150-
supplierFactors,
151-
});
152-
153146
// Get the supplierid with the lowest factor
154147
selectedSupplierId = supplierFactors[0].supplierId;
155148
let lowestFactor = supplierFactors[0].factor;
@@ -241,17 +234,27 @@ function incrementAllocation(
241234
volumeGroupId: string,
242235
supplierId: string,
243236
allocation: number,
237+
deps: Deps,
244238
) {
245239
const groupAllocations = map.get(volumeGroupId) ?? {};
246240
groupAllocations[supplierId] =
247241
(groupAllocations[supplierId] ?? 0) + allocation;
248242
map.set(volumeGroupId, groupAllocations);
243+
deps.logger.info({
244+
description: "Updated allocations for volume group and supplier",
245+
volumeGroupId,
246+
groupAllocations,
247+
});
249248
}
250249

251250
async function saveAllocations(
252251
deps: Deps,
253252
volumeGroupAllocations: VolumeGroupAllocation,
254253
) {
254+
deps.logger.info({
255+
description: "Saving supplier allocations for volume groups",
256+
volumeGroupAllocations,
257+
});
255258
for (const [volumeGroupId, allocations] of volumeGroupAllocations) {
256259
for (const [supplierId, allocation] of Object.entries(allocations)) {
257260
await updateSupplierAllocation(
@@ -291,6 +294,11 @@ export default function createSupplierAllocatorHandler(deps: Deps): SQSHandler {
291294
deps,
292295
);
293296

297+
deps.logger.info({
298+
description: "Resolved supplier details from config",
299+
supplierDetails,
300+
});
301+
294302
incrementAllocation(
295303
volumeGroupAllocations,
296304
supplierDetails?.volumeGroupId ?? "unknown",

lambdas/supplier-allocator/src/services/supplier-config.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,6 @@ function evaluateContraint(
199199
constraintValue: number,
200200
operator: string,
201201
): boolean {
202-
console.log(
203-
`Evaluating constraint: actualValue ${actualValue}, constraintValue ${constraintValue}, operator ${operator}`,
204-
);
205202
switch (operator) {
206203
case "EQUALS": {
207204
return actualValue === constraintValue;

lambdas/supplier-allocator/src/services/supplier-quotas.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { DailyAllocation, OverallAllocation } from "@internal/datastore";
22
import { SupplierAllocation } from "@nhsdigital/nhs-notify-event-schemas-supplier-config";
33
import { Deps } from "../config/deps";
4+
import { de } from "zod/v4/locales";
45

56
export async function calculateSupplierAllocatedFactor(
67
supplierAllocations: SupplierAllocation[],
@@ -45,6 +46,11 @@ export async function updateSupplierAllocation(
4546
const overallAllocation =
4647
await deps.supplierQuotasRepo.getOverallAllocation(volumeGroupId);
4748
if (overallAllocation) {
49+
deps.logger.info({
50+
description: "Existing overall allocation found for volume group",
51+
volumeGroupId,
52+
overallAllocation,
53+
});
4854
await deps.supplierQuotasRepo.updateOverallAllocation(
4955
volumeGroupId,
5056
supplierId,
@@ -58,6 +64,12 @@ export async function updateSupplierAllocation(
5864
[supplierId]: newAllocation,
5965
},
6066
};
67+
deps.logger.info({
68+
description:
69+
"No overall allocation found for volume group, creating new one",
70+
volumeGroupId,
71+
newOverallAllocation,
72+
});
6173
await deps.supplierQuotasRepo.putOverallAllocation(newOverallAllocation);
6274
}
6375
const dailyAllocationDate = new Date().toISOString().split("T")[0]; // Get current date in YYYY-MM-DD format

0 commit comments

Comments
 (0)