Skip to content

Commit 30bbf5a

Browse files
authored
chore(batch): exclude deprecated code from coverage (#4152)
1 parent a59db36 commit 30bbf5a

File tree

6 files changed

+13
-636
lines changed

6 files changed

+13
-636
lines changed

docs/features/batch.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ Processing batches from SQS works in three stages:
108108
3. Use **`processPartialResponse`** to kick off processing
109109

110110
!!! note
111-
By default, the batch processor will process messages in parallel, which does not guarantee the order of processing. If you need to process messages in order, set the [`processInParallel` option to `false`](#sequential-async-processing), or use [`SqsFifoPartialProcessor` for SQS FIFO queues](#fifo-queues).
111+
By default, the batch processor will process messages in parallel, which does not guarantee the order of processing. If you need to process messages in order, set the [`processInParallel` option to `false`](#sequential-processing), or use [`SqsFifoPartialProcessor` for SQS FIFO queues](#fifo-queues).
112112

113113
=== "index.ts"
114114

@@ -235,7 +235,7 @@ By default, we catch any exception raised by your record handler function. This
235235
--8<--
236236
```
237237

238-
1. Any exception works here. See [extending BatchProcessorSync section, if you want to override this behavior.](#extending-batchprocessor)
238+
1. Any exception works here. See [extending `BatchProcessor` section, if you want to override this behavior.](#extending-batchprocessor)
239239

240240
2. Exceptions raised in `recordHandler` will propagate to `process_partial_response`. <br/><br/> We catch them and include each failed batch item identifier in the response dictionary (see `Sample response` tab).
241241

@@ -411,7 +411,7 @@ Use the `BatchProcessor` directly in your function to access a list of all retur
411411

412412
Within your `recordHandler` function, you might need access to the Lambda context to determine how much time you have left before your function times out.
413413

414-
We can automatically inject the [Lambda context](https://docs.aws.amazon.com/lambda/latest/dg/typescript-context.html){target="_blank"} into your `recordHandler` as optional second argument if you register it when using `BatchProcessorSync` or the `processPartialResponseSync` function.
414+
We can automatically inject the [Lambda context](https://docs.aws.amazon.com/lambda/latest/dg/typescript-context.html){target="_blank"} into your `recordHandler` as optional second argument if you pass it to the `processPartialResponse` function.
415415

416416
```typescript hl_lines="12 27"
417417
--8<-- "examples/snippets/batch/accessLambdaContext.ts"
@@ -444,15 +444,15 @@ Let's suppose you'd like to add a metric named `BatchRecordFailures` for each ba
444444
--8<-- "examples/snippets/batch/extendingFailure.ts"
445445
```
446446

447-
### Sequential async processing
447+
### Sequential processing
448448

449449
By default, the `BatchProcessor` processes records in parallel using `Promise.all()`. However, if you need to preserve the order of records, you can set the `processInParallel` option to `false` to process records sequentially.
450450

451451
!!! important "If the `processInParallel` option is not provided, the `BatchProcessor` will process records in parallel."
452452

453453
When processing records from SQS FIFO queues, we recommend using the [`SqsFifoPartialProcessor`](#fifo-queues) class, which guarantees ordering of records and implements a short-circuit mechanism to skip processing records from a different message group ID.
454454

455-
```typescript hl_lines="8 17" title="Sequential async processing"
455+
```typescript hl_lines="8 17" title="Sequential processing"
456456
--8<-- "examples/snippets/batch/sequentialAsyncProcessing.ts"
457457
```
458458

@@ -487,7 +487,7 @@ classDiagram
487487
* **`processRecord()`** – If you need to implement asynchronous logic, use this method, otherwise define it in your class with empty logic
488488
* **`processRecordSync()`** – handles all processing logic for each individual message of a batch, including calling the `recordHandler` (`this.handler`)
489489

490-
You can then use this class as a context manager, or pass it to `processPartialResponseSync` to process the records in your Lambda handler function.
490+
You can then pass this class to `processPartialResponse` to process the records in your Lambda handler function.
491491

492492
```typescript hl_lines="21 35 55 60 72 85" title="Creating a custom batch processor"
493493
--8<-- "examples/snippets/batch/customPartialProcessor.ts"
@@ -507,7 +507,7 @@ You can use Tracer to create subsegments for each batch record processed. To do
507507

508508
## Testing your code
509509

510-
As there is no external calls, you can unit test your code with `BatchProcessorSync` quite easily.
510+
As there is no external calls, you can unit test your code with `BatchProcessor` quite easily.
511511

512512
**Example**:
513513

packages/batch/src/BasePartialProcessor.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -106,20 +106,6 @@ abstract class BasePartialProcessor {
106106
* Before and after processing, the processor will call the prepare and clean methods respectively.
107107
*/
108108
public async process(): Promise<(SuccessResponse | FailureResponse)[]> {
109-
/**
110-
* If this is a sync processor, user should have called processSync instead,
111-
* so we call the method early to throw the error early thus failing fast.
112-
*
113-
* The type casting is necessary to ensure that we have test coverage for the
114-
* block of code that throws the error, without having to change the return type
115-
* of the method. This is because this call will always throw an error.
116-
*/
117-
if (this.constructor.name === 'BatchProcessorSync') {
118-
return (await this.processRecord(this.records[0])) as (
119-
| SuccessResponse
120-
| FailureResponse
121-
)[];
122-
}
123109
this.prepare();
124110

125111
// Default to `true` if `processInParallel` is not specified.

packages/batch/src/BatchProcessorSync.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ import type { BaseRecord, FailureResponse, SuccessResponse } from './types.js';
8282
* @param eventType The type of event to process (SQS, Kinesis, DynamoDB)
8383
* @deprecated Use {@link BasePartialBatchProcessor} instead, this class is deprecated and will be removed in the next major version.
8484
*/
85-
class BatchProcessorSync extends BasePartialBatchProcessor {
85+
/* v8 ignore start */ class BatchProcessorSync extends BasePartialBatchProcessor {
8686
/**
8787
* @throws {BatchProcessingError} This method is not implemented for asynchronous processing.
8888
*
@@ -120,6 +120,6 @@ class BatchProcessorSync extends BasePartialBatchProcessor {
120120
return this.failureHandler(record, error as Error);
121121
}
122122
}
123-
}
123+
} /* v8 ignore stop */
124124

125125
export { BatchProcessorSync };

packages/batch/src/processPartialResponseSync.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,9 @@ import type {
9999
* @param processor Batch processor instance to handle the batch processing
100100
* @param options Batch processing options, which can vary with chosen batch processor implementation
101101
*/
102-
const processPartialResponseSync = <T extends BasePartialBatchProcessor>(
102+
/* v8 ignore start */ const processPartialResponseSync = <
103+
T extends BasePartialBatchProcessor,
104+
>(
103105
event: { Records: BaseRecord[] },
104106
recordHandler: CallableFunction,
105107
processor: T,
@@ -114,6 +116,6 @@ const processPartialResponseSync = <T extends BasePartialBatchProcessor>(
114116
processor.processSync();
115117

116118
return processor.response();
117-
};
119+
}; /* v8 ignore stop */
118120

119121
export { processPartialResponseSync };

packages/batch/tests/unit/BatchProcessorSync.test.ts

Lines changed: 0 additions & 270 deletions
This file was deleted.

0 commit comments

Comments
 (0)