Previously, our Redis abstraction only worked with strings because it
only dealt with the somewhat nebulous concept of message metadata. Now
that we also want to use it for concrete types, it makes sense to bake
in automatic serialization from and deserialization to those types. This
frees consumers from the responsibility of having to serialize to a
Redis-friendly format manually.
This change achieves that aim by making the db methods generic. `db.set`
gets a type parameter that is `Serialize` and the getters get one that
is `DeserializeOwned`.
The EmailAddress type was only being used in some places, which meant
some places that weren't using it had to call `validate::email_address`
manually. This change spreads it throughout most of the project, so
that almost everywhere gets to benefit from strong typing.
The only place I decided to leave it alone was the provider layer, where
some providers have their own `EmailAddress` struct. I could have
aliased it at that layer too, but by that point addresses are just dumb
strings anyway so it didn't seem worth it.
There is a bunch of minor fixes going on in this PR.
Fix#173
Add some debug logs for notifications in case we need it (probably would be good to only show them when we have some debug flag on or something)
Notification JSON may come in different shapes, nested or not nested, so I added functionality to accept both. That logic might me a little fragile so let me know what you think.
Fixes#10Fixes#99
Connects to #116
This was my first experience messing with the queues part of the service, I thought dealing with these issues first would make the experience smoother. I added the standard logging and error handling with the failure crate just like the rest of the lib.
Since our errors were very much centered around requests and rocket, we have some fields that don't really make sense for the queues process, like the http code, so let me know what you think about that and if the queues process should have a different error format. I also did another minor change to the errors: now the response JSON will return a number for code and errno, instead of a string.
For logging, I implemented an AppErrorFields so that we get better structured logs for our AppErrors. I used slog_scope to make it easier to have a global logger for the queues process, let me know what you think about that... In the README.md for that crate, they have some warnings about it not being the best idea all the time, but anyways, I thought it was neat and worked well for our case.
Finally, when I started working in the queues they were not really working due to parsing errors, you will see that I changed a little bit the SQS Notification struct, that was for parsing to work, also I created a notification-dev queue in the AWS Console, because it didn't exist yet, I think everything is working fine now.