generated from ran-isenberg/aws-lambda-handler-cookbook
-
Notifications
You must be signed in to change notification settings - Fork 13
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
docs(stream_processor): complete docstrings #81
Merged
Merged
Changes from all commits
Commits
Show all changes
73 commits
Select commit
Hold shift + click to select a range
ba6c401
chore: support for cdk watch to speedup dev
heitorlessa 01bb800
fix: ensure pytest only searches tests folder
heitorlessa a452f86
chore: cdk watch for infra too
heitorlessa 57fc38e
chore: use getpass over outdated getlogin
heitorlessa 880834e
chore: allow branches with _
heitorlessa 6d5fa6d
chore: standardize stream resource names
heitorlessa 409b58e
chore: add hello world stream proc lambda
heitorlessa afbac00
chore: add watch target in makefile
heitorlessa 8d7dc71
chore: make product models independent
heitorlessa 1821ef9
chore: remove stream specific schema for now
heitorlessa 956a2e1
chore(domain): create skeleton to notify updates
heitorlessa 657bdb8
chore: add placeholder code for handler
heitorlessa a622cf2
chore: add placeholder unit test
heitorlessa 5cb8b49
chore: rename stream processor to align w/ crud
heitorlessa 68788d0
chore: add format-fix, fix yapf errors
heitorlessa ba92b7f
fix(tests): stack not found when running integ
heitorlessa e7b59b7
chore: align handler and fn handler name w/ crud
heitorlessa 11ab329
chore: add mypy boto3 events dev dep
heitorlessa 6b85eb7
feat: add initial DAL protocol and eventbridge
heitorlessa 6c746bf
refactor: use status field over change_status since it's a notificati…
heitorlessa 689e09e
refactor: move test doubles and fixtures to conftest
heitorlessa 013b608
chore: test product_notifications
heitorlessa c340352
chore: add EventReceipt output model
heitorlessa 1dd1fb0
chore: ignore .idea dir
heitorlessa c38a33c
chore: create and use Event model
heitorlessa d2bd0b7
chore: use generic container for emit
heitorlessa fa546f0
chore: fix event serialization; cleanup
heitorlessa 2723fbf
chore: future note for event slicing
heitorlessa aa75844
chore: disable sockets for unit test
heitorlessa e9f3aa4
chore: add eventbridge provider test skeleton
heitorlessa ab590c2
chore: change to ProductChangeNotification
heitorlessa b90175f
chore: infer event structure from any model
heitorlessa e3115b2
chore: cleanup
heitorlessa 865fb4b
chore: test event structure and model to event conversions
heitorlessa 903d069
chore: adjust comment on event name
heitorlessa 5ba71d3
chore: complete eventbridge contract tests
heitorlessa 2d327bf
chore: remove dead code
heitorlessa f209601
chore: chunk maximum allowed events
heitorlessa 6dc4954
chore: test chunk logic separately
heitorlessa 86258eb
chore: linting
heitorlessa ed3a029
Merge branch 'main' into stream_processor
heitorlessa bd714c6
refactor: move standalones to functions.py; complete coverage
heitorlessa c8a5b55
refactor: move standalones to functions.py; complete coverage
heitorlessa 7e219ed
fix(mypy): narrow typing
heitorlessa 0112d0c
chore: enable pydantic plugin for mypy
heitorlessa 24206bd
chore: explicit typed dict type as mypy can't infer
heitorlessa c6e8c48
chore: explicit type as mypy can't infer
heitorlessa 4a0aaef
chore: actually apply pydantic plugin; skip pytest_socket missing py.…
heitorlessa cd157e9
chore: make pr fixes
heitorlessa fd003d7
refactor: rename dal to integrations
heitorlessa 1841f95
docs(domain): add initial docstrings
heitorlessa 9fcf867
chore: add mkdocs and mkdocstrings for documentation
heitorlessa 9c17f07
docs(handlers): add docstring for process_stream
heitorlessa e1f6476
docs(domain): use markdown to create anchor
heitorlessa be733bc
docs: increase indentation to improve nav
heitorlessa 6cc898c
docs(handler): add integrations section
heitorlessa bddc7b4
docs(domain): add integration section
heitorlessa 0d5728b
docs(models): add Pydantic models
heitorlessa 5ce39a3
docs(stream_processor): handlers first
heitorlessa 106f84b
docs(models): docstring pydantic models for API docs
heitorlessa a8cb6c5
docs(integrations): docstring constants for API docs
heitorlessa de577ca
docs(events): docstring to standalone functions
heitorlessa 7b62dc1
docs(events): docstring product change handler
heitorlessa 7602e09
docs: add integrations; API docs rendering adjusts
heitorlessa cf82f1b
docs(api): include exceptions; add base exception
heitorlessa 1d51a21
chore: move leftover comments to functions; linting
heitorlessa cf557d9
docs(api): docstring EventProvider
heitorlessa 7d278ab
docs(api): docstring interfaces
heitorlessa c297f51
docs(api): docstring eventbridge provider
heitorlessa 27f6044
refactor(events): move emit logic to base
heitorlessa 7b935fe
Merge branch 'main' into stream_processor
heitorlessa 6c27c67
docs(api): document standard Event and EventMetadata
heitorlessa de6f465
docs: readd homepage index
heitorlessa 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 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 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 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 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 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 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 |
---|---|---|
@@ -1,32 +1,72 @@ | ||
from abc import ABC, abstractmethod | ||
from typing import Any, Generic, TypeVar | ||
|
||
from product.stream_processor.integrations.events.functions import build_events_from_models | ||
from product.stream_processor.integrations.events.models.input import Event | ||
from product.stream_processor.integrations.events.models.output import EventReceipt | ||
|
||
T = TypeVar('T') | ||
|
||
# negative look ahead (?|char). Don't try to match the start of the string and any underscore that follows e.g., `_<name>` and `__<name>` | ||
|
||
# full regex: ((?!^)(?<!_)[A-Z][a-z]+|(?<=[a-z0-9])[A-Z]) | ||
# ProductNotification -> Product_Notification | ||
# ProductNotificationV2 -> Product_Notification_V2 | ||
# ProductHTTP -> Product_HTTP | ||
|
||
|
||
class EventProvider(ABC): | ||
"""ABC for an Event Provider that send events to a destination.""" | ||
|
||
@abstractmethod | ||
def send(self, payload: list[Event]) -> EventReceipt: | ||
"""Sends list of events to an Event Provider. | ||
|
||
Parameters | ||
---------- | ||
payload : list[Event] | ||
List of events to send. | ||
|
||
Returns | ||
------- | ||
EventReceipt | ||
Receipts for unsuccessfully and successfully published events. | ||
|
||
Raises | ||
------ | ||
NotificationDeliveryError | ||
When one or more events could not be delivered. | ||
""" | ||
... | ||
|
||
|
||
class EventHandler(ABC, Generic[T]): | ||
|
||
def __init__(self, provider: EventProvider, event_source: str) -> None: | ||
"""ABC to handle event manipulation from a model, and publishing through a provider. | ||
|
||
Parameters | ||
---------- | ||
provider : EventProvider | ||
Event Provider to publish events through. | ||
event_source : str | ||
Event source name, e.g., 'myorg.service.feature' | ||
""" | ||
self.provider = provider | ||
self.event_source = event_source | ||
|
||
@abstractmethod | ||
def emit(self, payload: list[T], metadata: dict[str, Any] | None = None, correlation_id='') -> EventReceipt: | ||
... | ||
"""Emits product change notifications using registered provider, along with additional metadata or specific correlation ID. | ||
|
||
Parameters | ||
---------- | ||
payload : list[T] | ||
List of product change notifications models to be sent. | ||
metadata : dict[str, Any] | None, optional | ||
Additional metadata to be injected into the event before sending, by default None | ||
correlation_id : str, optional | ||
Correlation ID to inject in event metadata. We generate one if not provided. | ||
|
||
Returns | ||
------- | ||
EventReceipt | ||
Receipts for unsuccessfully and successfully published events. | ||
""" | ||
event_payload = build_events_from_models( | ||
models=payload, metadata=metadata, correlation_id=correlation_id, | ||
event_source=self.event_source) # type: ignore[type-var] # T will be defined by its implementation; see ProductChangeNotificationHandler | ||
return self.provider.send(payload=event_payload) | ||
This file contains 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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
"""Constants related to events integration (event handler and event providers)""" | ||
DEFAULT_EVENT_VERSION = 'v1' | ||
EVENTBRIDGE_PROVIDER_MAX_EVENTS_ENTRY = 10 |
This file contains 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 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 |
---|---|---|
@@ -1,9 +1,25 @@ | ||
from product.stream_processor.integrations.events.models.output import EventReceiptFail | ||
|
||
|
||
class ProductNotificationDeliveryError(Exception): | ||
class NotificationDeliveryError(Exception): | ||
|
||
def __init__(self, message: str, receipts: list[EventReceiptFail]): | ||
"""Exception raised when a notification delivery fails. | ||
|
||
Parameters | ||
---------- | ||
message : str | ||
error message | ||
receipts : list[EventReceiptFail] | ||
list of receipts failed notification deliveries along with details | ||
""" | ||
super().__init__(message) | ||
self.message = message | ||
self.receipts = receipts | ||
|
||
|
||
class ProductChangeNotificationDeliveryError(NotificationDeliveryError): | ||
"""Raised when one or all product change notification deliveries fail.""" | ||
|
||
def __init__(self, message: str, receipts: list[EventReceiptFail]): | ||
super().__init__(message, receipts) |
This file contains 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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you really like them tabs :)