mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-23 08:51:30 -05:00
Refactored the initialisation of the redis client to follow the model used in the StatsdClient.
Basically wrapped the client so we can enable/disable, exception handle and so on.
This commit is contained in:
@@ -4,7 +4,6 @@ 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
|
||||||
@@ -16,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
|
||||||
|
|
||||||
|
|
||||||
@@ -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_store = FlaskRedis()
|
redis_store = RedisClient()
|
||||||
|
|
||||||
clients = Clients()
|
clients = Clients()
|
||||||
|
|
||||||
|
|||||||
20
app/clients/redis/redis_client.py
Normal file
20
app/clients/redis/redis_client.py
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
from flask.ext.redis import FlaskRedis
|
||||||
|
|
||||||
|
|
||||||
|
class RedisClient:
|
||||||
|
active = False
|
||||||
|
redis_store = FlaskRedis()
|
||||||
|
|
||||||
|
def init_app(self, app):
|
||||||
|
self.active = app.config.get('REDIS_ENABLED')
|
||||||
|
|
||||||
|
if self.active:
|
||||||
|
self.redis_store.init_app(app)
|
||||||
|
|
||||||
|
def set(self, key, value):
|
||||||
|
if self.active:
|
||||||
|
self.redis_store.set(key, value)
|
||||||
|
|
||||||
|
def get(self, key):
|
||||||
|
if self.active:
|
||||||
|
self.redis_store.get(key)
|
||||||
@@ -36,6 +36,7 @@ from app.schemas import (
|
|||||||
)
|
)
|
||||||
from app.service.utils import service_allowed_to_send_to
|
from app.service.utils import service_allowed_to_send_to
|
||||||
from app.utils import pagination_links
|
from app.utils import pagination_links
|
||||||
|
from app import redis_store
|
||||||
|
|
||||||
notifications = Blueprint('notifications', __name__)
|
notifications = Blueprint('notifications', __name__)
|
||||||
|
|
||||||
@@ -205,6 +206,8 @@ 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):
|
||||||
|
redis_store.set('key1', 'value')
|
||||||
|
|
||||||
if notification_type not in ['sms', 'email']:
|
if notification_type not in ['sms', 'email']:
|
||||||
assert False
|
assert False
|
||||||
|
|
||||||
|
|||||||
@@ -132,7 +132,7 @@ class Config(object):
|
|||||||
STATSD_HOST = "statsd.hostedgraphite.com"
|
STATSD_HOST = "statsd.hostedgraphite.com"
|
||||||
STATSD_PORT = 8125
|
STATSD_PORT = 8125
|
||||||
|
|
||||||
REDIS_ENABLED = True
|
REDIS_ENABLED = False
|
||||||
REDIS_URL = "redis://localhost:6379/0"
|
REDIS_URL = "redis://localhost:6379/0"
|
||||||
|
|
||||||
SENDING_NOTIFICATIONS_TIMEOUT_PERIOD = 259200
|
SENDING_NOTIFICATIONS_TIMEOUT_PERIOD = 259200
|
||||||
|
|||||||
Reference in New Issue
Block a user