Skip to content

Feature request: ability to not throw error on full batch failure #2122

Closed
@dreamorosi

Description

@dreamorosi

Use case

Note

This feature request comes from #1785

Currently when using the Batch Processor utility, if all the records in a batch are marked as failed the utility throws a BatchProcessingError.

Taking into consideration that the utility is supposed to be used with partial failure reporting, a Lambda function that throws an error is functionally equal to a partial failure that reports all items as failed in the sense that all the items in that batch are retried as a result.

While we initially implemented this as an error to reflect the full batch failure in the operational metrics (i.e. function runtime errors), there are cases such as when processing small batches that this behavior can skew the metrics due to higher chances of a full batch to fail.

To accommodate these use cases, as well as those customers who simply want to avoid throwing an error, we should add a new throwOnFullBatchFailure option to the utility that allows customers to opt out of the error throwing mechanism.

Solution/User Experience

I haven't spent a lot of time thinking on where the new option should land, but the two options that come to mind are either when initializing the processor:

const processor = new BatchProcessor(
  EventType.SQS,
  {
    throwOnFullBatchFailure: false
});

or in the process function itself:

export const handler = async (
  event: SQSEvent,
  context: Context
): Promise<SQSBatchResponse> => {
  return processPartialResponse(event, recordHandler, processor, {
    context,
    throwOnFullBatchFailure: false
  });
};

Without looking at the internal implementation - which will inevitably inform the decision - I'm more inclined towards the second option for additional granularity (i.e. I might want to reuse the same BatchProcessor across multiple routes) and also because we already have a configuration object parameter that we can extend.

Alternative solutions

No response

Acknowledgment

Future readers

Please react with 👍 and your use case to help us understand customer demand.

Metadata

Metadata

Assignees

Labels

batchThis item relates to the Batch Processing UtilitycompletedThis item is complete and has been merged/shippedfeature-requestThis item refers to a feature request for an existing or new utilityhelp-wantedWe would really appreciate some support from community for this one

Type

No type

Projects

Status

Shipped

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions