Skip to content

feat(batch): reduce boilerplate with process_partial_response #2090

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

Merged

Conversation

heitorlessa
Copy link
Contributor

@heitorlessa heitorlessa commented Apr 6, 2023

Issue number: #2083

Summary

New process_partial_response and async_process_partial_response higher level functions.

Changes

Please provide a summary of what's being changed

Add two new higher-order functions to reduce boilerplate and make it less error-prone for new customers using Batch, where the additional return often cause confusion.

This addition has the added benefit of reducing decorators therefore call stacks too (more memory/CPU efficient).

User experience

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

Before

image

After

image

Async

image

Checklist

If your change doesn't seem to apply, please leave them unchecked.

  • Meet tenets criteria
  • I have performed a self-review of this change
  • Changes have been tested
  • Changes are documented
  • PR title follows conventional commit semantics
  • Update examples to use new higher-level function first
  • Add FAQ section on when to choose this vs batch_processor and async_batch_processor, and uncertain decision about future deprecation for the more verbose DX
  • Review Custom Batch Processor and other areas to favour new higher-level function
  • Replace all code snippets using batch_processor with process_partial_response
  • Replace all code snippets using async_batch_processor with async_process_partial_response
  • Fix Pydantic examples aren't working
  • Review each processor intro for the no longer necessary .response()
  • Review any call out to batch_processor and async_batch_processor
  • Review this
    • You will not have access to the processed messages within the Lambda Handler; use context manager for that.

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.

@heitorlessa heitorlessa requested a review from a team as a code owner April 6, 2023 15:25
@heitorlessa heitorlessa requested review from rubenfonseca and removed request for a team April 6, 2023 15:25
@boring-cyborg boring-cyborg bot added the tests label Apr 6, 2023
@pull-request-size pull-request-size bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Apr 6, 2023
@heitorlessa heitorlessa requested review from leandrodamascena and removed request for rubenfonseca April 6, 2023 15:25
@heitorlessa heitorlessa marked this pull request as draft April 6, 2023 15:25
@github-actions github-actions bot added the feature New feature or functionality label Apr 6, 2023
@heitorlessa
Copy link
Contributor Author

Converting to Draft as I still need to work on a doc revamp ;)

PS: check this out @BakasuraRCE, I'm sure you'll enjoy the new slim DX.

replace all examples with batch_processor with process_partial_response and its async equivalent.
renamed 'As a decorator' code sections to make it explicitly legacy.
add new section 'Recommended' using the new behaviour

fixed all incorrect Pydantic examples while replacing batch_processor
@boring-cyborg boring-cyborg bot added the documentation Improvements or additions to documentation label Apr 6, 2023
@pull-request-size pull-request-size bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Apr 6, 2023
@codecov-commenter
Copy link

codecov-commenter commented Apr 7, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: +0.01 🎉

Comparison is base (ec1b346) 97.45% compared to head (93fa497) 97.46%.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #2090      +/-   ##
===========================================
+ Coverage    97.45%   97.46%   +0.01%     
===========================================
  Files          146      147       +1     
  Lines         6748     6781      +33     
  Branches       477      478       +1     
===========================================
+ Hits          6576     6609      +33     
  Misses         136      136              
  Partials        36       36              
Impacted Files Coverage Δ
aws_lambda_powertools/utilities/batch/__init__.py 100.00% <100.00%> (ø)
aws_lambda_powertools/utilities/batch/base.py 94.70% <100.00%> (-0.42%) ⬇️
...ws_lambda_powertools/utilities/batch/decorators.py 100.00% <100.00%> (ø)
aws_lambda_powertools/utilities/batch/types.py 81.25% <100.00%> (+8.52%) ⬆️
...wertools/utilities/idempotency/persistence/base.py 99.39% <100.00%> (ø)
...ools/utilities/idempotency/persistence/dynamodb.py 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

* develop:
  fix(batch): handle early validation errors for pydantic models (poison pill) aws-powertools#2091 (aws-powertools#2099)
  update changelog with latest changes
  docs(homepage): remove banner for end-of-support v1 (aws-powertools#2098)
  chore(deps-dev): bump aws-cdk-lib from 2.72.1 to 2.73.0 (aws-powertools#2097)
  chore(deps-dev): bump filelock from 3.10.7 to 3.11.0 (aws-powertools#2094)
  chore(deps-dev): bump coverage from 7.2.2 to 7.2.3 (aws-powertools#2092)
  chore(deps-dev): bump aws-cdk from 2.72.1 to 2.73.0 (aws-powertools#2093)
  chore(deps-dev): bump mypy-boto3-cloudformation from 1.26.60 to 1.26.108 (aws-powertools#2095)

Signed-off-by: heitorlessa <[email protected]>
@heitorlessa heitorlessa force-pushed the feat/reduce-batch-boilerplate branch from 93fa497 to 120aab9 Compare April 7, 2023 12:33
@heitorlessa
Copy link
Contributor Author

Notes for maintainers:

Additional tech debt paid

  • Fixed syntax highlighting for all code snippets
  • Fixed incorrect code snippets for Pydantic integration
  • Moved code snippets using decorators as-is under examples (still needs to be refactored as our docs theme)
  • Renamed As a decorator to As a decorator (legacy) to keep customers informed along with a FAQ -- whichever way they find batch_processor they'll know the reason.

@heitorlessa heitorlessa marked this pull request as ready for review April 7, 2023 12:37
@heitorlessa
Copy link
Contributor Author

spoke to @leandrodamascena who's on public holiday today - approved to go.

@heitorlessa heitorlessa merged commit 60d0363 into aws-powertools:develop Apr 7, 2023
@heitorlessa heitorlessa deleted the feat/reduce-batch-boilerplate branch April 7, 2023 13:36
@github-actions github-actions bot added the pending-release Fix or implementation already in dev waiting to be released label Apr 7, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Apr 7, 2023

This is now released under 2.12.0 version!

@github-actions github-actions bot removed the pending-release Fix or implementation already in dev waiting to be released label Apr 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation feature New feature or functionality size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants