Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 27 additions & 3 deletions apps/webapp/app/v3/services/batchTriggerV3.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,29 @@ function chunkArray<T>(items: T[], size: number): T[][] {
}
return chunks;
}

// Summarizes a task-identifier -> items grouping for logging, without including the items
// themselves (each item is `{ task, payload, options }`, and `options.metadata` is arbitrary
// customer data that must never be written to logs whole).
export function summarizeItemsByTask(itemsByTask: Record<string, unknown[]>): {
taskIdentifiers: string[];
itemCountsByTask: Record<string, number>;
totalItemCount: number;
} {
const itemCountsByTask: Record<string, number> = {};
let totalItemCount = 0;

for (const [taskIdentifier, items] of Object.entries(itemsByTask)) {
itemCountsByTask[taskIdentifier] = items.length;
totalItemCount += items.length;
}

return {
taskIdentifiers: Object.keys(itemsByTask),
itemCountsByTask,
totalItemCount,
};
}
const ASYNC_BATCH_PROCESS_SIZE_THRESHOLD = 20;
const MAX_ATTEMPTS = 10;

Expand Down Expand Up @@ -409,9 +432,10 @@ export class BatchTriggerV3Service extends BaseService {
{} as Record<string, typeof body.items>
);

logger.debug("[BatchTriggerV2][call] Grouped items by task identifier", {
itemsByTask,
});
logger.debug(
"[BatchTriggerV2][call] Grouped items by task identifier",
summarizeItemsByTask(itemsByTask)
);

const idempotencyKeyLookups = Object.entries(itemsByTask).flatMap(([taskIdentifier, items]) => {
const idempotencyKeys = Array.from(
Expand Down
38 changes: 38 additions & 0 deletions apps/webapp/test/batchTriggerV3ItemLogSummary.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { describe, expect, test } from "vitest";
import { summarizeItemsByTask } from "~/v3/services/batchTriggerV3.server";

describe("summarizeItemsByTask", () => {
test("returns counts and task identifiers without the underlying items", () => {
const itemsByTask = {
"my-task": [
{ task: "my-task", payload: { secret: "value" }, options: { metadata: { pii: "yes" } } },
{ task: "my-task", payload: { secret: "value-2" }, options: {} },
],
"other-task": [{ task: "other-task", payload: {}, options: {} }],
};

const summary = summarizeItemsByTask(itemsByTask);

expect(summary).toEqual({
taskIdentifiers: ["my-task", "other-task"],
itemCountsByTask: { "my-task": 2, "other-task": 1 },
totalItemCount: 3,
});

// The summary must never contain the raw items, their payloads, or their options -
// just identifiers and counts.
const serialized = JSON.stringify(summary);
expect(serialized).not.toContain("payload");
expect(serialized).not.toContain("secret");
expect(serialized).not.toContain("metadata");
expect(serialized).not.toContain("pii");
});

test("returns empty collections when there are no idempotent items", () => {
expect(summarizeItemsByTask({})).toEqual({
taskIdentifiers: [],
itemCountsByTask: {},
totalItemCount: 0,
});
});
});