From dfdffd4d65aed753cf9c098d3b55bbebd7c3988d Mon Sep 17 00:00:00 2001 From: erikayao93 Date: Fri, 28 Jul 2023 21:31:28 +0000 Subject: [PATCH 1/2] Update process to pass only context to handler --- 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..5256218ff8 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 { 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.'); From 6204eaeef280e07adf92fab0aeb24aba4e0935eb Mon Sep 17 00:00:00 2001 From: Andrea Amorosi Date: Sat, 29 Jul 2023 13:40:51 +0200 Subject: [PATCH 2/2] Update packages/batch/tests/helpers/handlers.ts --- packages/batch/tests/helpers/handlers.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/batch/tests/helpers/handlers.ts b/packages/batch/tests/helpers/handlers.ts index 5256218ff8..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 { Context } from 'aws-lambda'; +import type { Context } from 'aws-lambda'; const sqsRecordHandler = (record: SQSRecord): string => { const body = record.body;