-
Notifications
You must be signed in to change notification settings - Fork 429
feat(batch): add async_batch_processor for concurrent processing #1724
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
leandrodamascena
merged 20 commits into
aws-powertools:develop
from
BakasuraRCE:feat-async-btach-processor
Feb 10, 2023
Merged
Changes from 9 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
0941771
feat: implement AsyncBatchProcessor
f38cc9f
fix: missed async def
c5fb4b6
fix(tests): typos
2a83c21
refactor(tests): restore imports order
4d6c0f3
docs(examples): add async and batch processor examples
6cce749
refactor: make single inheritance
edbc1bd
Merge branch 'develop' into feat-async-btach-processor
heitorlessa fe91461
Update aws_lambda_powertools/utilities/batch/base.py
BakasuraRCE 5596509
feat: better implementation of async loop
f63cadc
Merge branch 'develop' into feat-async-btach-processor
heitorlessa 3d64789
chore: fmt and linting
heitorlessa 4c2d7d1
Merge branch 'develop' into feat-async-btach-processor
heitorlessa 65e347f
chore: expand notes on async_process being an sync callable
heitorlessa b58048f
chore: cleanup notes, closure name, and leaner short-circuiting
heitorlessa 55e50be
chore: fix docstrings for BatchProcessor and AsyncBatchProcessor
heitorlessa 4e28bb2
docs: remove sync for now, revamp async example
heitorlessa 1640d3a
docs: add new section for async processing and details
heitorlessa 0a79aac
chore: add httpx dev dependency for batch docs; update deps
heitorlessa c9e6068
fix poetry.lock to merge
leandrodamascena ab28204
fix poetry.lock to merge
leandrodamascena File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
examples/batch_processing/src/getting_started_async_batch_processor.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from aws_lambda_powertools.utilities.batch import async_batch_processor, EventType, AsyncBatchProcessor | ||
from aws_lambda_powertools.utilities.data_classes.sqs_event import SQSRecord | ||
from aws_lambda_powertools.utilities.typing import LambdaContext | ||
|
||
|
||
async def async_record_handler(record: SQSRecord): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. np: what would be a realistic example here? maybe an async crawler? As part of docs refactoring, we haven't reached Batch yet, we're trying to include more complete examples. |
||
""" | ||
Process here each record | ||
""" | ||
payload: str = record.body | ||
if not payload: | ||
raise ValueError | ||
# code code code | ||
|
||
|
||
processor = AsyncBatchProcessor(event_type=EventType.SQS) | ||
|
||
|
||
@async_batch_processor(record_handler=async_record_handler, processor=processor) | ||
async def lambda_handler(event, context: LambdaContext): | ||
return processor.response() |
21 changes: 21 additions & 0 deletions
21
examples/batch_processing/src/getting_started_batch_processor.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from aws_lambda_powertools.utilities.batch import EventType, batch_processor, BatchProcessor | ||
from aws_lambda_powertools.utilities.data_classes.sqs_event import SQSRecord | ||
from aws_lambda_powertools.utilities.typing import LambdaContext | ||
|
||
|
||
def record_handler(record: SQSRecord): | ||
""" | ||
Process here each record | ||
""" | ||
payload: str = record.body | ||
if not payload: | ||
raise ValueError | ||
# code code code | ||
|
||
|
||
processor = BatchProcessor(event_type=EventType.SQS) | ||
|
||
|
||
@batch_processor(record_handler=record_handler, processor=processor) | ||
def lambda_handler(event, context: LambdaContext): | ||
return processor.response() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.