Pushed the cache increment into the shared code that persists notifications.

Much simpler implementation, inc code removed from tasks and V1/V2 rest clients.
This commit is contained in:
Martyn Inglis
2016-11-22 12:53:20 +00:00
parent 58bbc5a5aa
commit 9e2ba9ee81
9 changed files with 52 additions and 167 deletions

View File

@@ -28,7 +28,7 @@ from app.notifications.process_notifications import persist_notification
from app.service.utils import service_allowed_to_send_to
from app.statsd_decorators import statsd
from app import redis_store
from app.clients.redis import cache_key
from app.clients.redis import daily_limit_cache_key
@notify_celery.task(name="process-job")
@@ -164,8 +164,6 @@ def send_sms(self,
"RETRY FAILED: task send_sms failed for notification".format(
notification.get('job', None),
notification.get('row_number', None)), e)
else:
redis_store.incr(cache_key(service_id))
@notify_celery.task(bind=True, name="send-email", max_retries=5, default_retry_delay=300)
@@ -216,5 +214,3 @@ def send_email(self, service_id,
"RETRY FAILED: task send_email failed for notification".format(
notification.get('job', None),
notification.get('row_number', None)), e)
else:
redis_store.incr(cache_key(service_id))

View File

@@ -1,5 +1,5 @@
from datetime import datetime
def cache_key(service_id):
def daily_limit_cache_key(service_id):
return "{}-{}-{}".format(str(service_id), datetime.utcnow().strftime("%Y-%m-%d"), "count")

View File

@@ -4,8 +4,9 @@ from flask import current_app
from notifications_utils.renderers import PassThrough
from notifications_utils.template import Template
from app import DATETIME_FORMAT
from app import DATETIME_FORMAT, redis_store
from app.celery import provider_tasks
from app.clients import redis
from app.dao.notifications_dao import dao_create_notification, dao_delete_notifications_and_history_by_id
from app.models import SMS_TYPE, Notification, KEY_TYPE_TEST, EMAIL_TYPE
from app.notifications.validators import check_sms_content_char_count
@@ -61,6 +62,7 @@ def persist_notification(template_id,
job_row_number=job_row_number
)
dao_create_notification(notification)
redis_store.incr(redis.daily_limit_cache_key(service_id))
return notification

View File

@@ -246,7 +246,6 @@ 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.incr(redis.cache_key(service.id))
return jsonify(
data=get_notification_return_data(
notification_id,

View File

@@ -10,7 +10,7 @@ from app.clients import redis
def check_service_message_limit(key_type, service):
if key_type != KEY_TYPE_TEST:
cache_key = redis.cache_key(service.id)
cache_key = redis.daily_limit_cache_key(service.id)
service_stats = redis_store.get(cache_key)
if not service_stats:
service_stats = services_dao.fetch_todays_total_message_count(service.id)