1) It's incr not inc on the redis client, so renamed the calls everywhere
2) Redis returns bytes/string rather than an int if the value stored is an int. Cast the result to an int before use. Not you can set up the GET to do this transparently but I've not done this as we *may * use GETS for non-int and the callback sets up the cast for the connection not the call.
After we have written to the database and placed it on a deliver queue we count it in the cache against the service.
This is the equivalent of doing it at the end of the API call.
These means that the cache count is on Notifications in the database NOT notifications sent to providers. If the provider fails to accept the notification, it still counts.
I think this is correct, as they have done the work to send it so we should count it, though there is an argument that we should count them on sending?
- Uses Redis cache to check for current count
- If not present then sets the value based on the database state
- Any Redis errors are swallowed. Cache failures should NOT fail the request.
Two different versions of 0059 were merged.
`0059_set_services_to_active` was merged first, so this renames my
migration to `0060`, so it goes in afterwards.
this means that any errors will cause the entire thing to roll back
unfortunately, to do this we have to circumvent our regular code, which calls commit a lot, and lazily loads a lot of things, which will flush, and cause the version decorators to fail. so we have to write a lot of stuff by hand and re-select the service (even though it's already been queried) just to populate the api_keys and templates relationship on it
A letter type was added to the `enum` in the `Template` model at the
same it was added to the `Notification` model. But the migration was
only done for the `notifications` table, not the `templates` table.
See: https://github.com/alphagov/notifications-api/commit/25db1bce#diff-516aab258e161fc65e7564dabd2c625aR19
This commit does the migration to add `letter` as a possible value for
the `template_type` column, which is a bit fiddly because `enum`s.
Before:
```
notification_api=# select enum_range(null::template_type);
enum_range
-------------
{sms,email}
(1 row)
```
After upgrade:
```
notification_api=# select enum_range(null::template_type);
enum_range
--------------------
{sms,email,letter}
(1 row)
```
After downgrade
```
notification_api=# select enum_range(null::template_type);
enum_range
-------------
{sms,email}
(1 row)
```