@aws-lambda-powertools/batch
Version:
The batch processing package for the Powertools for AWS Lambda (TypeScript) library.
79 lines • 3.37 kB
TypeScript
import { BatchProcessorSync } from './BatchProcessorSync.js';
import type { EventSourceDataClassTypes, FailureResponse, SuccessResponse } from './types.js';
/**
* Batch processor for SQS FIFO queues
*
* This class extends the {@link BatchProcessorSync} class and provides
* a mechanism to process records from SQS FIFO queues synchronously.
*
* By default, we will stop processing at the first failure and mark unprocessed messages as failed to preserve ordering.
*
* However, this behavior may not be optimal for customers who wish to proceed with processing messages from a different group ID.
*
* @example
* ```typescript
* import {
* BatchProcessor,
* EventType,
* processPartialResponseSync,
* } from '@aws-lambda-powertools/batch';
* import type { SQSRecord, SQSHandler } from 'aws-lambda';
*
* const processor = new BatchProcessor(EventType.SQS);
*
* const recordHandler = async (record: SQSRecord): Promise<void> => {
* const payload = JSON.parse(record.body);
* };
*
* export const handler: SQSHandler = async (event, context) =>
* processPartialResponseSync(event, recordHandler, processor, {
* context,
* });
* ```
*/
declare class SqsFifoPartialProcessor extends BatchProcessorSync {
#private;
constructor();
/**
* Handles a failure for a given record.
* Adds the current group ID to the set of failed group IDs if `skipGroupOnError` is true.
* @param record - The record that failed.
* @param exception - The error that occurred.
* @returns The failure response.
*/
failureHandler(record: EventSourceDataClassTypes, exception: Error): FailureResponse;
/**
* Process a record with a synchronous handler
*
* This method orchestrates the processing of a batch of records synchronously
* for SQS FIFO queues.
*
* The method calls the prepare hook to initialize the processor and then
* iterates over each record in the batch, processing them one by one.
*
* If one of them fails and `skipGroupOnError` is not true, the method short circuits
* the processing and fails the remaining records in the batch.
*
* If one of them fails and `skipGroupOnError` is true, then the method fails the current record
* if the message group has any previous failure, otherwise keeps processing.
*
* Then, it calls the clean hook to clean up the processor and returns the
* processed records.
*/
processSync(): (SuccessResponse | FailureResponse)[];
/**
* Starting from the first failure index, fail all remaining messages regardless
* of their group ID.
*
* This short circuit mechanism is used when we detect a failed message in the batch.
*
* Since messages in a FIFO queue are processed in order, we must stop processing any
* remaining messages in the batch to prevent out-of-order processing.
*
* @param firstFailureIndex Index of first message that failed
* @param processedRecords Array of response items that have been processed both successfully and unsuccessfully
*/
protected shortCircuitProcessing(firstFailureIndex: number, processedRecords: (SuccessResponse | FailureResponse)[]): (SuccessResponse | FailureResponse)[];
}
export { SqsFifoPartialProcessor };
//# sourceMappingURL=SqsFifoPartialProcessor.d.ts.map