Skip to content
Merged
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
1 change: 1 addition & 0 deletions packages/batch/src/SqsFifoPartialProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ class SqsFifoPartialProcessor extends BatchProcessorSync {
*/
public processSync(): (SuccessResponse | FailureResponse)[] {
this.prepare();
this.#processor.prepare();

const processedRecords: (SuccessResponse | FailureResponse)[] = [];
let currentIndex = 0;
Expand Down
1 change: 1 addition & 0 deletions packages/batch/src/SqsFifoPartialProcessorAsync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ class SqsFifoPartialProcessorAsync extends BatchProcessor {
*/
public async process(): Promise<(SuccessResponse | FailureResponse)[]> {
this.prepare();
this.#processor.prepare();

const processedRecords: (SuccessResponse | FailureResponse)[] = [];
let currentIndex = 0;
Expand Down
8 changes: 8 additions & 0 deletions packages/batch/src/SqsFifoProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ class SqsFifoProcessor {
this.#failedGroupIds.add(group);
}

/**
* Prepares the processor for a new batch of messages.
*/
public prepare(): void {
this.#currentGroupId = undefined;
this.#failedGroupIds.clear();
}

/**
* Sets the current group ID for the message being processed.
*
Expand Down
36 changes: 36 additions & 0 deletions packages/batch/tests/unit/SqsFifoPartialProcessor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,4 +185,40 @@ describe('SQS FIFO Processors', () => {
});
});
}

it('continues processing and moves to the next group when `skipGroupOnError` is true', async () => {
// Prepare
const firstRecord = sqsRecordFactory('fail', '1');
const secondRecord = sqsRecordFactory('success', '2');
const firstRecordAgain = sqsRecordFactory('success', '1');
const event1 = {
Records: [firstRecord, secondRecord],
};
const event2 = {
Records: [firstRecordAgain],
};
const processor = new SqsFifoPartialProcessor();
const fn = vi.fn((record) => {
if (record.body.includes('fail')) {
throw new Error('Processing failed');
}

return record;
});

// Act
const result1 = processPartialResponseSync(event1, fn, processor, {
skipGroupOnError: true,
throwOnFullBatchFailure: false,
});
const result2 = processPartialResponseSync(event2, fn, processor, {
skipGroupOnError: true,
throwOnFullBatchFailure: false,
});

// Assess
expect(result1.batchItemFailures.length).toBe(1);
expect(result2.batchItemFailures.length).toBe(0);
expect(fn).toHaveBeenCalledTimes(3);
});
});
Loading