mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-02 09:26:08 -05:00
Couple of bugs squashed.
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.
This commit is contained in:
@@ -151,7 +151,7 @@ def send_sms(self,
|
||||
e
|
||||
)
|
||||
else:
|
||||
redis_store.inc(cache_key(service_id))
|
||||
redis_store.incr(cache_key(service_id))
|
||||
|
||||
|
||||
@notify_celery.task(bind=True, name="send-email", max_retries=5, default_retry_delay=300)
|
||||
@@ -192,4 +192,4 @@ def send_email(self, service_id,
|
||||
e
|
||||
)
|
||||
else:
|
||||
redis_store.inc(cache_key(service_id))
|
||||
redis_store.incr(cache_key(service_id))
|
||||
|
||||
@@ -21,10 +21,10 @@ class RedisClient:
|
||||
if raise_exception:
|
||||
raise e
|
||||
|
||||
def inc(self, key, raise_exception=False):
|
||||
def incr(self, key, raise_exception=False):
|
||||
if self.active:
|
||||
try:
|
||||
return self.redis_store.inc(key)
|
||||
return self.redis_store.incr(key)
|
||||
except Exception as e:
|
||||
current_app.logger.exception(e)
|
||||
if raise_exception:
|
||||
|
||||
@@ -246,7 +246,7 @@ def send_notification(notification_type):
|
||||
|
||||
notification_id = create_uuid() if saved_notification is None else saved_notification.id
|
||||
notification.update({"template_version": template.version})
|
||||
redis_store.inc(redis.cache_key(service.id))
|
||||
redis_store.incr(redis.cache_key(service.id))
|
||||
return jsonify(
|
||||
data=get_notification_return_data(
|
||||
notification_id,
|
||||
|
||||
@@ -15,7 +15,7 @@ def check_service_message_limit(key_type, service):
|
||||
if not service_stats:
|
||||
service_stats = services_dao.fetch_todays_total_message_count(service.id)
|
||||
redis_store.set(cache_key, service_stats, ex=3600)
|
||||
if service_stats >= service.message_limit:
|
||||
if int(service_stats) >= service.message_limit:
|
||||
raise TooManyRequestsError(service.message_limit)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user