-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Description
In AWS, there is a limit (262144 bytes) on the size of an SQS message. Right now, we manage that limit by catching raw AWS exception and reraising our own, MessageTooLarge.
However, I believe there is a better way, — a more abstract and portable.
- Let us define a refined type meaning a string with certain max length:
LimitedString[262144]; - Use it as
internal_typeof the SQS queue classes; - Define typecasts
LimitedString[262144] → strand, most importantly,str → LimitedString[262144]. The latter is actually checking thelen()if the argument and, if it is below limits, raises aStringTooLarge, or something. - Because of typecasting transitivity, we get working typecasting path like this:
pydantic.BaseModel → dict → str → LimitedString[262144]. - Now, this validation check will happen every time we are submitting data to SQS, automatically.
send_many()actually has the same 262144 bytes limitation but for the whole workload. In other words, you can send multiple messages faster but each of them will have to be smaller. I believe we should create another string type for this with tighter constraint — for the sake of reliability, but that may be a subject of discussion.
With all that said, https://github.com/antonagestam/phantom-types can be helpful.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels