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

Feature request: Ability to not throw error on full batch failure #608

Open
2 tasks done
hjgraca opened this issue Jul 4, 2024 · 3 comments
Open
2 tasks done

Feature request: Ability to not throw error on full batch failure #608

hjgraca opened this issue Jul 4, 2024 · 3 comments
Labels
batch Batch processing utility feature-request New or enhancements to existing features help wanted Tasks you want help from anyone to move forward

Comments

@hjgraca
Copy link
Contributor

hjgraca commented Jul 4, 2024

Use case

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

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 behaviour 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 policy RaiseOnBatchFailure (or similar) option to the utility that allows customers to opt out of the error throwing mechanism.

More information here: aws-powertools/powertools-lambda-typescript#2122 (comment)

Solution/User Experience

public class CustomSqsRecordHandler : ISqsRecordHandler 
{
    public async Task<RecordHandlerResult> HandleAsync(SQSEvent.SQSMessage record, CancellationToken cancellationToken)
    {
         var product = JsonSerializer.Deserialize<Product>(record.Body);
         return await Task.FromResult(RecordHandlerResult.None); 
     }
}


[BatchProcessor(RecordHandler = typeof(CustomSqsRecordHandler), 
ErrorHandlingPolicy = BatchProcessorErrorHandlingPolicy.RaiseOnBatchFailure)]
public BatchItemFailuresResponse HandlerUsingAttribute(SQSEvent _)
{
    return SqsBatchProcessor.Result.BatchItemFailuresResponse; 
}

Alternative solutions

No response

Acknowledgment

@hjgraca hjgraca added feature-request New or enhancements to existing features triage Pending triage from maintainers labels Jul 4, 2024
@dreamorosi dreamorosi added help wanted Tasks you want help from anyone to move forward batch Batch processing utility and removed triage Pending triage from maintainers labels Jul 22, 2024
@lachriz-aws
Copy link
Contributor

I'm happy to take a look at this. Will try to set time aside in the comings weeks.

@hjgraca
Copy link
Contributor Author

hjgraca commented Aug 23, 2024

thank you @lachriz-aws

@lachriz-aws
Copy link
Contributor

Hi @hjgraca, I have now submitted a PR draft with a proposed solution to this, see #646 - let me know what you think.

I'm of course happy to update the docs as well (but wanted to wait until we have agreed on how the final solution should look like).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
batch Batch processing utility feature-request New or enhancements to existing features help wanted Tasks you want help from anyone to move forward
Projects
Status: 📋 Backlog
Development

No branches or pull requests

3 participants