Skip to content

Feature request: Batch processing Typed decorator support #1033

@hjgraca

Description

@hjgraca

Use case

Full support for TypedRecordHandler and TypedRecordHandlerWithContext

    [BatchProcessor(TypedRecordHandler = typeof(TypedSqsRecordHandler))]
    public BatchItemFailuresResponse HandlerUsingTypedAttribute(SQSEvent _)
    {
    	return TypedSqsBatchProcessor.Result.BatchItemFailuresResponse; // (4)!
    }
    [BatchProcessor(TypedRecordHandlerWithContext = typeof(ProductHandlerWithContext))]
    public BatchItemFailuresResponse ProcessWithContext(SQSEvent sqsEvent, ILambdaContext context)
    {
        return TypedSqsBatchProcessor.Result.BatchItemFailuresResponse;
    }

Solution/User Experience

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)!
    }

Alternative solutions

Acknowledgment

Metadata

Metadata

Assignees

Labels

area/batchBatch utilityfeature-requestNew or enhancements to existing features

Type

No type

Projects

Status

👀 In review

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions