Skip to content

Commit 4fbcc9f

Browse files
debug logging
1 parent 7ee04fa commit 4fbcc9f

3 files changed

Lines changed: 27 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
@@ -137,19 +137,11 @@ async function getSupplierFromConfig(
137137
suppliersForPack.some((supplier) => supplier.id === alloc.supplier),
138138
);
139139

140-
console.log("Supplier allocations for pack", {
141-
supplierAllocationsForPack,
142-
});
143-
144140
supplierFactors = await calculateSupplierAllocatedFactor(
145141
supplierAllocationsForPack,
146142
deps,
147143
);
148144

149-
console.log("Supplier factors calculated for allocation", {
150-
supplierFactors,
151-
});
152-
153145
// Get the supplierid with the lowest factor
154146
selectedSupplierId = supplierFactors[0].supplierId;
155147
let lowestFactor = supplierFactors[0].factor;
@@ -241,17 +233,27 @@ function incrementAllocation(
241233
volumeGroupId: string,
242234
supplierId: string,
243235
allocation: number,
236+
deps: Deps,
244237
) {
245238
const groupAllocations = map.get(volumeGroupId) ?? {};
246239
groupAllocations[supplierId] =
247240
(groupAllocations[supplierId] ?? 0) + allocation;
248241
map.set(volumeGroupId, groupAllocations);
242+
deps.logger.info({
243+
description: "Updated allocations for volume group and supplier",
244+
volumeGroupId,
245+
groupAllocations,
246+
});
249247
}
250248

251249
async function saveAllocations(
252250
deps: Deps,
253251
volumeGroupAllocations: VolumeGroupAllocation,
254252
) {
253+
deps.logger.info({
254+
description: "Saving supplier allocations for volume groups",
255+
volumeGroupAllocations,
256+
});
255257
for (const [volumeGroupId, allocations] of volumeGroupAllocations) {
256258
for (const [supplierId, allocation] of Object.entries(allocations)) {
257259
await updateSupplierAllocation(
@@ -291,11 +293,17 @@ export default function createSupplierAllocatorHandler(deps: Deps): SQSHandler {
291293
deps,
292294
);
293295

296+
deps.logger.info({
297+
description: "Resolved supplier details from config",
298+
supplierDetails,
299+
});
300+
294301
incrementAllocation(
295302
volumeGroupAllocations,
296303
supplierDetails?.volumeGroupId ?? "unknown",
297304
supplierSpec.supplierId,
298305
1,
306+
deps,
299307
);
300308

301309
supplier = supplierSpec.supplierId;

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: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ export async function updateSupplierAllocation(
4545
const overallAllocation =
4646
await deps.supplierQuotasRepo.getOverallAllocation(volumeGroupId);
4747
if (overallAllocation) {
48+
deps.logger.info({
49+
description: "Existing overall allocation found for volume group",
50+
volumeGroupId,
51+
overallAllocation,
52+
});
4853
await deps.supplierQuotasRepo.updateOverallAllocation(
4954
volumeGroupId,
5055
supplierId,
@@ -58,6 +63,12 @@ export async function updateSupplierAllocation(
5863
[supplierId]: newAllocation,
5964
},
6065
};
66+
deps.logger.info({
67+
description:
68+
"No overall allocation found for volume group, creating new one",
69+
volumeGroupId,
70+
newOverallAllocation,
71+
});
6172
await deps.supplierQuotasRepo.putOverallAllocation(newOverallAllocation);
6273
}
6374
const dailyAllocationDate = new Date().toISOString().split("T")[0]; // Get current date in YYYY-MM-DD format

0 commit comments

Comments
 (0)