mirror of
https://github.com/GSA/notifications-api.git
synced 2026-09-11 10:28:55 -04:00
Initial SPIKE into redis for cache
This commit is contained in:
@@ -15,6 +15,7 @@ from app.clients.sms.firetext import FiretextClient
|
|||||||
from app.clients.sms.loadtesting import LoadtestingClient
|
from app.clients.sms.loadtesting import LoadtestingClient
|
||||||
from app.clients.email.aws_ses import AwsSesClient
|
from app.clients.email.aws_ses import AwsSesClient
|
||||||
from app.clients.statsd.statsd_client import StatsdClient
|
from app.clients.statsd.statsd_client import StatsdClient
|
||||||
|
from app.clients.redis.redis_client import RedisClient
|
||||||
from app.encryption import Encryption
|
from app.encryption import Encryption
|
||||||
|
|
||||||
|
|
||||||
@@ -30,6 +31,7 @@ mmg_client = MMGClient()
|
|||||||
aws_ses_client = AwsSesClient()
|
aws_ses_client = AwsSesClient()
|
||||||
encryption = Encryption()
|
encryption = Encryption()
|
||||||
statsd_client = StatsdClient()
|
statsd_client = StatsdClient()
|
||||||
|
redis_client = RedisClient()
|
||||||
|
|
||||||
clients = Clients()
|
clients = Clients()
|
||||||
|
|
||||||
@@ -48,6 +50,7 @@ def create_app(app_name=None):
|
|||||||
db.init_app(application)
|
db.init_app(application)
|
||||||
ma.init_app(application)
|
ma.init_app(application)
|
||||||
statsd_client.init_app(application)
|
statsd_client.init_app(application)
|
||||||
|
redis_client.init_app(application)
|
||||||
logging.init_app(application, statsd_client)
|
logging.init_app(application, statsd_client)
|
||||||
firetext_client.init_app(application, statsd_client=statsd_client)
|
firetext_client.init_app(application, statsd_client=statsd_client)
|
||||||
loadtest_client.init_app(application, statsd_client=statsd_client)
|
loadtest_client.init_app(application, statsd_client=statsd_client)
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
import redis
|
||||||
|
|
||||||
|
|
||||||
|
class RedisClient:
|
||||||
|
def init_app(self, app, *args, **kwargs):
|
||||||
|
self.active = app.config.get('REDIS_ENABLED')
|
||||||
|
self.redis = None
|
||||||
|
|
||||||
|
if self.active:
|
||||||
|
self.redis = redis.StrictRedis(
|
||||||
|
app.config.get('REDIS_HOST'),
|
||||||
|
app.config.get('REDIS_PORT')
|
||||||
|
)
|
||||||
|
|
||||||
|
def set(self, key, value):
|
||||||
|
self.redis.set(key, value)
|
||||||
|
|
||||||
|
def get(self, key):
|
||||||
|
return self.redis.get(key)
|
||||||
|
|
||||||
|
def incr(self, key):
|
||||||
|
return self.redis.incr(key)
|
||||||
@@ -44,6 +44,8 @@ from app.errors import (
|
|||||||
InvalidRequest
|
InvalidRequest
|
||||||
)
|
)
|
||||||
|
|
||||||
|
from app import redis_client
|
||||||
|
|
||||||
register_errors(notifications)
|
register_errors(notifications)
|
||||||
|
|
||||||
|
|
||||||
@@ -204,6 +206,9 @@ def get_notification_statistics_for_day():
|
|||||||
|
|
||||||
@notifications.route('/notifications/<string:notification_type>', methods=['POST'])
|
@notifications.route('/notifications/<string:notification_type>', methods=['POST'])
|
||||||
def send_notification(notification_type):
|
def send_notification(notification_type):
|
||||||
|
|
||||||
|
current_app.logger.info(redis_client.incr(api_user.service_id))
|
||||||
|
|
||||||
if notification_type not in ['sms', 'email']:
|
if notification_type not in ['sms', 'email']:
|
||||||
assert False
|
assert False
|
||||||
|
|
||||||
|
|||||||
@@ -132,6 +132,10 @@ class Config(object):
|
|||||||
STATSD_HOST = "statsd.hostedgraphite.com"
|
STATSD_HOST = "statsd.hostedgraphite.com"
|
||||||
STATSD_PORT = 8125
|
STATSD_PORT = 8125
|
||||||
|
|
||||||
|
REDIS_ENABLED = True
|
||||||
|
REDIS_HOST = "localhost"
|
||||||
|
REDIS_PORT = 6379
|
||||||
|
|
||||||
SENDING_NOTIFICATIONS_TIMEOUT_PERIOD = 259200
|
SENDING_NOTIFICATIONS_TIMEOUT_PERIOD = 259200
|
||||||
|
|
||||||
SIMULATED_EMAIL_ADDRESSES = ('simulate-delivered@notifications.service.gov.uk',
|
SIMULATED_EMAIL_ADDRESSES = ('simulate-delivered@notifications.service.gov.uk',
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ celery==3.1.23
|
|||||||
monotonic==1.2
|
monotonic==1.2
|
||||||
statsd==3.2.1
|
statsd==3.2.1
|
||||||
jsonschema==2.5.1
|
jsonschema==2.5.1
|
||||||
|
redis==2.10.5
|
||||||
|
|
||||||
git+https://github.com/alphagov/notifications-python-client.git@1.3.0#egg=notifications-python-client==1.3.0
|
git+https://github.com/alphagov/notifications-python-client.git@1.3.0#egg=notifications-python-client==1.3.0
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user