powertools-lambda-dotnet icon indicating copy to clipboard operation
powertools-lambda-dotnet copied to clipboard

feat: batch typed decorator

Open hjgraca opened this issue 3 months ago • 4 comments

Please provide the issue number

Issue number: closes #1033

Summary

Changes

Full support for TypedRecordHandler and TypedRecordHandlerWithContext

public class Product
    {
        public int Id { get; set; }
        public string? Name { get; set; }
        public decimal Price { get; set; }
    }

    public class TypedSqsRecordHandler : ITypedRecordHandler<Product> // (1)!
    {
    	public async Task<RecordHandlerResult> HandleAsync(Product product, CancellationToken cancellationToken)
    	{
    		 /*
    		 * Your business logic with automatic deserialization.
    		 * If an exception is thrown, the item will be marked as a partial batch item failure.
             */

             Logger.LogInformation($"Processing product {product.Id} - {product.Name} (${product.Price})");

             if (product.Id == 4) // (2)!
             {
                 throw new ArgumentException("Error on id 4");
             }

             return await Task.FromResult(RecordHandlerResult.None); // (3)!
         }

	}

    [BatchProcessor(TypedRecordHandler = typeof(TypedSqsRecordHandler))]
    public BatchItemFailuresResponse HandlerUsingTypedAttribute(SQSEvent _)
    {
    	return TypedSqsBatchProcessor.Result.BatchItemFailuresResponse; // (4)!
    }

User experience

Please share what the user experience looks like before and after this change

Checklist

Please leave checklist items unchecked if they do not apply to your change.

Is this a breaking change?

RFC issue number:

Checklist:

  • [ ] Migration process documented
  • [ ] Implement warnings (if it can live side by side)

Acknowledgment

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

hjgraca avatar Oct 08 '25 16:10 hjgraca

the documentation file was wrongly formated fixed, so looks like the whole file changed but in reality just one line

hjgraca avatar Oct 08 '25 16:10 hjgraca

Codecov Report

:x: Patch coverage is 78.57143% with 48 lines in your changes missing coverage. Please review. :white_check_mark: Project coverage is 78.33%. Comparing base (12573e5) to head (a83f3d0). :warning: Report is 5 commits behind head on develop.

Files with missing lines Patch % Lines
...ertools.BatchProcessing/BatchProcessorAttribute.cs 80.35% 17 Missing and 5 partials :warning:
...sing/Internal/TypedBatchProcessingAspectHandler.cs 85.50% 6 Missing and 4 partials :warning:
...cessing/Kinesis/TypedKinesisEventBatchProcessor.cs 42.85% 8 Missing :warning:
...sing/DynamoDb/TypedDynamoDbStreamBatchProcessor.cs 64.28% 5 Missing :warning:
...ools.BatchProcessing/Sqs/TypedSqsBatchProcessor.cs 78.57% 3 Missing :warning:
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1034      +/-   ##
===========================================
+ Coverage    78.17%   78.33%   +0.16%     
===========================================
  Files          298      299       +1     
  Lines        12012    12231     +219     
  Branches      1443     1473      +30     
===========================================
+ Hits          9390     9581     +191     
- Misses        2160     2181      +21     
- Partials       462      469       +7     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

codecov[bot] avatar Oct 08 '25 17:10 codecov[bot]

cc @lachriz-aws

hjgraca avatar Oct 20 '25 12:10 hjgraca