mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-20 23:41:17 -05:00
Adding Flask-Redis to the project.
[https://pypi.python.org/pypi/Flask-Redis/0.1.0](https://pypi.python.org/pypi/Flask-Redis/0.1.0) Initial addition as we think about redis as cache.
This commit is contained in:
@@ -4,6 +4,7 @@ import os
|
|||||||
from flask import request, url_for, g, jsonify
|
from flask import request, url_for, g, jsonify
|
||||||
from flask import Flask, _request_ctx_stack
|
from flask import Flask, _request_ctx_stack
|
||||||
from flask.ext.sqlalchemy import SQLAlchemy
|
from flask.ext.sqlalchemy import SQLAlchemy
|
||||||
|
from flask.ext.redis import FlaskRedis
|
||||||
from flask_marshmallow import Marshmallow
|
from flask_marshmallow import Marshmallow
|
||||||
from monotonic import monotonic
|
from monotonic import monotonic
|
||||||
from werkzeug.local import LocalProxy
|
from werkzeug.local import LocalProxy
|
||||||
@@ -15,7 +16,6 @@ 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
|
||||||
|
|
||||||
|
|
||||||
@@ -31,7 +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()
|
redis_store = FlaskRedis()
|
||||||
|
|
||||||
clients = Clients()
|
clients = Clients()
|
||||||
|
|
||||||
@@ -50,7 +50,6 @@ 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)
|
||||||
@@ -58,6 +57,7 @@ def create_app(app_name=None):
|
|||||||
aws_ses_client.init_app(application.config['AWS_REGION'], statsd_client=statsd_client)
|
aws_ses_client.init_app(application.config['AWS_REGION'], statsd_client=statsd_client)
|
||||||
notify_celery.init_app(application)
|
notify_celery.init_app(application)
|
||||||
encryption.init_app(application)
|
encryption.init_app(application)
|
||||||
|
redis_store.init_app(application)
|
||||||
clients.init_app(sms_clients=[firetext_client, mmg_client, loadtest_client], email_clients=[aws_ses_client])
|
clients.init_app(sms_clients=[firetext_client, mmg_client, loadtest_client], email_clients=[aws_ses_client])
|
||||||
|
|
||||||
register_blueprint(application)
|
register_blueprint(application)
|
||||||
|
|||||||
@@ -1,22 +0,0 @@
|
|||||||
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,7 +44,6 @@ from app.errors import (
|
|||||||
InvalidRequest
|
InvalidRequest
|
||||||
)
|
)
|
||||||
|
|
||||||
from app import redis_client
|
|
||||||
|
|
||||||
register_errors(notifications)
|
register_errors(notifications)
|
||||||
|
|
||||||
@@ -206,9 +205,6 @@ 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
|
||||||
|
|
||||||
|
|||||||
@@ -133,8 +133,7 @@ class Config(object):
|
|||||||
STATSD_PORT = 8125
|
STATSD_PORT = 8125
|
||||||
|
|
||||||
REDIS_ENABLED = True
|
REDIS_ENABLED = True
|
||||||
REDIS_HOST = "localhost"
|
REDIS_URL = "redis://localhost:6379/0"
|
||||||
REDIS_PORT = 6379
|
|
||||||
|
|
||||||
SENDING_NOTIFICATIONS_TIMEOUT_PERIOD = 259200
|
SENDING_NOTIFICATIONS_TIMEOUT_PERIOD = 259200
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +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
|
Flask-Redis==0.1.0
|
||||||
|
|
||||||
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