-
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
feat(stream_processor): initial version for processing product changes #76
Conversation
Signed-off-by: heitorlessa <lessa@amazon.co.uk>
Signed-off-by: heitorlessa <lessa@amazon.co.uk>
Signed-off-by: heitorlessa <lessa@amazon.co.uk>
Signed-off-by: heitorlessa <lessa@amazon.co.uk>
Signed-off-by: heitorlessa <lessa@amazon.co.uk>
Signed-off-by: heitorlessa <lessa@amazon.co.uk>
Signed-off-by: heitorlessa <lessa@amazon.co.uk>
Signed-off-by: heitorlessa <lessa@amazon.co.uk>
Signed-off-by: heitorlessa <lessa@amazon.co.uk>
Signed-off-by: heitorlessa <lessa@amazon.co.uk>
Signed-off-by: heitorlessa <lessa@amazon.co.uk>
Signed-off-by: heitorlessa <lessa@amazon.co.uk>
Signed-off-by: heitorlessa <lessa@amazon.co.uk>
Signed-off-by: heitorlessa <lessa@amazon.co.uk>
Signed-off-by: heitorlessa <lessa@amazon.co.uk>
Signed-off-by: heitorlessa <lessa@amazon.co.uk>
Signed-off-by: heitorlessa <lessa@amazon.co.uk>
792b6a6
to
e7b59b7
Compare
Signed-off-by: heitorlessa <lessa@amazon.co.uk>
Signed-off-by: heitorlessa <lessa@amazon.co.uk>
…on already Signed-off-by: heitorlessa <lessa@amazon.co.uk>
Signed-off-by: heitorlessa <lessa@amazon.co.uk>
Signed-off-by: heitorlessa <lessa@amazon.co.uk>
Signed-off-by: heitorlessa <lessa@amazon.co.uk>
Signed-off-by: heitorlessa <lessa@amazon.co.uk>
…typed Signed-off-by: heitorlessa <lessa@amazon.co.uk>
Signed-off-by: heitorlessa <lessa@amazon.co.uk>
Waiting for CI before I rename |
Signed-off-by: heitorlessa <lessa@amazon.co.uk>
I believe the deployment credentials error is because it's coming from my fork, and not as a branch from the repo. Everything else passed. Gonna add docstrings now but implementation wise is ready for review. |
@heitorlessa I'll need to port lots of code to the template , yikes. but thx for fixing lots of side issues |
@heitorlessa I forked your branch and it passes all tests . coverage is down 2% though |
sure thing. I'm working on docstrings now. Check how cool this looks ;) |
Signed-off-by: heitorlessa <lessa@amazon.co.uk>
Signed-off-by: heitorlessa <lessa@amazon.co.uk>
Signed-off-by: heitorlessa <lessa@amazon.co.uk>
Signed-off-by: heitorlessa <lessa@amazon.co.uk>
Signed-off-by: heitorlessa <lessa@amazon.co.uk>
Signed-off-by: heitorlessa <lessa@amazon.co.uk>
Signed-off-by: heitorlessa <lessa@amazon.co.uk>
when i run make docs i a 404 page, when i click on homepage link to the left, it works |
Signed-off-by: heitorlessa <lessa@amazon.co.uk>
Signed-off-by: heitorlessa <lessa@amazon.co.uk>
@@ -55,6 +55,12 @@ types-requests = "*" | |||
toml = "*" | |||
|
|||
|
|||
[tool.poetry.group.dev.dependencies] |
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.
we already have the group:
[tool.poetry.dev-dependencies]
so which is the best dev deps name?
@@ -18,7 +18,7 @@ def init(): | |||
os.environ[POWER_TOOLS_LOG_LEVEL] = 'DEBUG' | |||
os.environ['REST_API'] = 'https://www.ranthebuilder.cloud/api' | |||
os.environ['ROLE_ARN'] = 'arn:partition:service:region:account-id:resource-type:resource-id' | |||
os.environ['AWS_DEFAULT_REGION'] = 'us-east-1' # used for appconfig mocked boto calls | |||
os.environ['AWS_DEFAULT_REGION'] = os.environ.get('AWS_DEFAULT_REGION', 'us-east-1') # used for appconfig mocked boto calls |
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.
remove the appconfig comment, it's my bad :)
_pascal_to_snake_pattern = re.compile(rf'({_exclude_underscores}{_pascal_case}{_or}{_followed_by_lower_case_or_digit}') | ||
|
||
|
||
def convert_model_to_event_name(model_name: str) -> str: |
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.
i know that pydantic has support for automatic serializations thagt tranfser from whatever format to another
see this example:
def to_camel_lower_case(snake_str: str) -> str:
components = snake_str.split('_')
return components[0] + ''.join(x.capitalize() for x in components[1:])
then you add to the pydantic class this config. it means that when you do .model_dump it will run the to_camel_lower_case function automatically
class Config:
alias_generator = to_camel_lower_case
allow_population_by_field_name = False
|
||
T = TypeVar('T') | ||
|
||
_exclude_underscores = r'(?!^)(?<!_)' |
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.
functions is a bit of generic name ? maybe utils? or move the schema related ones to the schema folder?
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.
I chose functions
as a more narrow version of utils
. Similar to tests/.../data_builders.py
instead of utils.py
. That way I know where utility functions are, instead of bin packing into utils.py
.
Makes sense?
from product.models.products.product import ProductChangeNotification | ||
|
||
|
||
def generate_dynamodb_stream_events(product_id: str = '8c18c85a-0f10-4b73-b54a-07ab0d381018',) -> dict[str, Any]: |
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 move the generate_product_id from crud_utils.py and you use it instead of a default id
class EventMetadata(BaseModel): | ||
event_name: str | ||
event_source: str | ||
event_version: str |
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.
let's add a default value here?
|
||
|
||
class Event(BaseModel, Generic[AnyModel]): | ||
data: AnyModel |
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.
shouldnt the timestamp and version reside here? they are like a hint for parsing everything else
|
||
|
||
class EventReceiptFail(BaseModel): | ||
receipt_id: str |
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.
same here for field min length, so they are not empty
error_message = exc.response['Error']['Message'] | ||
|
||
receipt = EventReceiptFail(receipt_id='', error='error_message', details=exc.response['ResponseMetadata']) | ||
raise ProductNotificationDeliveryError(f'Failed to deliver all events: {error_message}', receipts=[receipt]) from exc |
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.
about the error handling here, if we raise the exception, we stop going over the batch right? shouldnt we do failed.extend(batch somehow) and do continue in the loop?
@heitorlessa top class code, really. but damn, this one was hard, lots of files and required concentration. |
closes #75
Summary
Initial skeleton to create stream processor to handle product updates coming from CRUD.
Changes
product/models/
)product/models/products
)product/models/products/validators
)product/stream_processor/domain_logic/constants.py
)handlers/stream_handler
tohandlers/product_stream
EventProvider
to receive Input EventEventReceipt
)put_events
to the max permittedINSERT
DynamoDB Stream eventREMOVE
DynamoDB Stream eventmkdocstrings
)Tasks for a separate PR due to size
unrelated but noticeable changes
cdk watch
to speed prototypingcdk.out
_
getpass.getuser()
over outdatedos.getlogin()
to take into account env vars (mine wasroot
, now it'slessa
)User experience
Checklist
If your change doesn't seem to apply, please leave them unchecked.
Is this a breaking change?
RFC issue number:
Checklist:
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.