Skip to content

Commit

Permalink
fix(batch): Update processor to pass only context to handler (#1637)
Browse files Browse the repository at this point in the history
* Update process to pass only context to handler

* Update packages/batch/tests/helpers/handlers.ts

---------

Co-authored-by: Andrea Amorosi <[email protected]>
  • Loading branch information
erikayao93 and dreamorosi authored Jul 29, 2023
1 parent 4318d6f commit 6fa09b2
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 12 deletions.
2 changes: 1 addition & 1 deletion packages/batch/src/AsyncBatchProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class AsyncBatchProcessor extends BasePartialBatchProcessor {
): Promise<SuccessResponse | FailureResponse> {
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) {
Expand Down
2 changes: 1 addition & 1 deletion packages/batch/src/BatchProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
13 changes: 3 additions & 10 deletions packages/batch/tests/helpers/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.');
Expand All @@ -82,10 +77,8 @@ const handlerWithContext = (

const asyncHandlerWithContext = async (
record: SQSRecord,
options: BatchProcessingOptions
context: Context
): Promise<string> => {
const context = options.context;

try {
if (context.getRemainingTimeInMillis() == 0) {
throw Error('No time remaining.');
Expand Down

0 comments on commit 6fa09b2

Please sign in to comment.