From 6fa09b2638bf247fd595db51ac3d1aa1252d3379 Mon Sep 17 00:00:00 2001 From: Erika Yao <71943596+erikayao93@users.noreply.github.com> Date: Sat, 29 Jul 2023 07:09:21 -0500 Subject: [PATCH] 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 --- packages/batch/src/AsyncBatchProcessor.ts | 2 +- packages/batch/src/BatchProcessor.ts | 2 +- packages/batch/tests/helpers/handlers.ts | 13 +++---------- 3 files changed, 5 insertions(+), 12 deletions(-) diff --git a/packages/batch/src/AsyncBatchProcessor.ts b/packages/batch/src/AsyncBatchProcessor.ts index 781c7f1c79..f4e02a327e 100644 --- a/packages/batch/src/AsyncBatchProcessor.ts +++ b/packages/batch/src/AsyncBatchProcessor.ts @@ -10,7 +10,7 @@ class AsyncBatchProcessor extends BasePartialBatchProcessor { ): Promise { try { const data = this.toBatchType(record, this.eventType); - const result = await this.handler(data, this.options); + const result = await this.handler(data, this.options?.context); return this.successHandler(record, result); } catch (error) { diff --git a/packages/batch/src/BatchProcessor.ts b/packages/batch/src/BatchProcessor.ts index 3d2a75a8da..fdab0c6f44 100644 --- a/packages/batch/src/BatchProcessor.ts +++ b/packages/batch/src/BatchProcessor.ts @@ -19,7 +19,7 @@ class BatchProcessor extends BasePartialBatchProcessor { public processRecord(record: BaseRecord): SuccessResponse | FailureResponse { try { const data = this.toBatchType(record, this.eventType); - const result = this.handler(data, this.options); + const result = this.handler(data, this.options?.context); return this.successHandler(record, result); } catch (error) { diff --git a/packages/batch/tests/helpers/handlers.ts b/packages/batch/tests/helpers/handlers.ts index 3a6d17b76a..0256129f9b 100644 --- a/packages/batch/tests/helpers/handlers.ts +++ b/packages/batch/tests/helpers/handlers.ts @@ -3,7 +3,7 @@ import type { KinesisStreamRecord, SQSRecord, } from 'aws-lambda'; -import type { BatchProcessingOptions } from '../../src/types'; +import type { Context } from 'aws-lambda'; const sqsRecordHandler = (record: SQSRecord): string => { const body = record.body; @@ -63,12 +63,7 @@ const asyncDynamodbRecordHandler = async ( return body; }; -const handlerWithContext = ( - record: SQSRecord, - options: BatchProcessingOptions -): string => { - const context = options.context; - +const handlerWithContext = (record: SQSRecord, context: Context): string => { try { if (context.getRemainingTimeInMillis() == 0) { throw Error('No time remaining.'); @@ -82,10 +77,8 @@ const handlerWithContext = ( const asyncHandlerWithContext = async ( record: SQSRecord, - options: BatchProcessingOptions + context: Context ): Promise => { - const context = options.context; - try { if (context.getRemainingTimeInMillis() == 0) { throw Error('No time remaining.');