Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(batch): Update processor to pass only context to handler #1637

Merged
merged 2 commits into from
Jul 29, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 { Context } from 'aws-lambda';
dreamorosi marked this conversation as resolved.
Show resolved Hide resolved

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