Skip to content

Commit 6fa09b2

Browse files
fix(batch): Update processor to pass only context to handler (#1637)
* Update process to pass only context to handler * Update packages/batch/tests/helpers/handlers.ts --------- Co-authored-by: Andrea Amorosi <[email protected]>
1 parent 4318d6f commit 6fa09b2

File tree

3 files changed

+5
-12
lines changed

3 files changed

+5
-12
lines changed

Diff for: packages/batch/src/AsyncBatchProcessor.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class AsyncBatchProcessor extends BasePartialBatchProcessor {
1010
): Promise<SuccessResponse | FailureResponse> {
1111
try {
1212
const data = this.toBatchType(record, this.eventType);
13-
const result = await this.handler(data, this.options);
13+
const result = await this.handler(data, this.options?.context);
1414

1515
return this.successHandler(record, result);
1616
} catch (error) {

Diff for: packages/batch/src/BatchProcessor.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class BatchProcessor extends BasePartialBatchProcessor {
1919
public processRecord(record: BaseRecord): SuccessResponse | FailureResponse {
2020
try {
2121
const data = this.toBatchType(record, this.eventType);
22-
const result = this.handler(data, this.options);
22+
const result = this.handler(data, this.options?.context);
2323

2424
return this.successHandler(record, result);
2525
} catch (error) {

Diff for: packages/batch/tests/helpers/handlers.ts

+3-10
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type {
33
KinesisStreamRecord,
44
SQSRecord,
55
} from 'aws-lambda';
6-
import type { BatchProcessingOptions } from '../../src/types';
6+
import type { Context } from 'aws-lambda';
77

88
const sqsRecordHandler = (record: SQSRecord): string => {
99
const body = record.body;
@@ -63,12 +63,7 @@ const asyncDynamodbRecordHandler = async (
6363
return body;
6464
};
6565

66-
const handlerWithContext = (
67-
record: SQSRecord,
68-
options: BatchProcessingOptions
69-
): string => {
70-
const context = options.context;
71-
66+
const handlerWithContext = (record: SQSRecord, context: Context): string => {
7267
try {
7368
if (context.getRemainingTimeInMillis() == 0) {
7469
throw Error('No time remaining.');
@@ -82,10 +77,8 @@ const handlerWithContext = (
8277

8378
const asyncHandlerWithContext = async (
8479
record: SQSRecord,
85-
options: BatchProcessingOptions
80+
context: Context
8681
): Promise<string> => {
87-
const context = options.context;
88-
8982
try {
9083
if (context.getRemainingTimeInMillis() == 0) {
9184
throw Error('No time remaining.');

0 commit comments

Comments
 (0)