mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-03 18:01:08 -05:00
Init the perf platform client, add logs and refactor payload methods
This commit is contained in:
@@ -66,6 +66,7 @@ def create_app(app_name=None):
|
|||||||
notify_celery.init_app(application)
|
notify_celery.init_app(application)
|
||||||
encryption.init_app(application)
|
encryption.init_app(application)
|
||||||
redis_store.init_app(application)
|
redis_store.init_app(application)
|
||||||
|
performance_platform_client.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)
|
||||||
|
|||||||
@@ -13,16 +13,24 @@ from app.utils import (
|
|||||||
|
|
||||||
class PerformancePlatformClient:
|
class PerformancePlatformClient:
|
||||||
|
|
||||||
|
@property
|
||||||
|
def active(self):
|
||||||
|
return self._active
|
||||||
|
|
||||||
|
@active.setter
|
||||||
|
def active(self, value):
|
||||||
|
self._active = value
|
||||||
|
|
||||||
def init_app(self, app):
|
def init_app(self, app):
|
||||||
self.active = app.config.get('PERFORMANCE_PLATFORM_ENABLED')
|
self._active = app.config.get('PERFORMANCE_PLATFORM_ENABLED')
|
||||||
if self.active:
|
if self.active:
|
||||||
self.bearer_token = app.config.get('PERFORMANCE_PLATFORM_TOKEN')
|
self.bearer_token = app.config.get('PERFORMANCE_PLATFORM_TOKEN')
|
||||||
self.performance_platform_url = current_app.config.get('PERFORMANCE_PLATFORM_URL')
|
self.performance_platform_url = app.config.get('PERFORMANCE_PLATFORM_URL')
|
||||||
|
|
||||||
def send_performance_stats(self, date, channel, count, period):
|
def send_performance_stats(self, date, channel, count, period):
|
||||||
if self.active:
|
if self.active:
|
||||||
payload = {
|
payload = {
|
||||||
'_timestamp': date,
|
'_timestamp': str(date),
|
||||||
'service': 'govuk-notify',
|
'service': 'govuk-notify',
|
||||||
'channel': channel,
|
'channel': channel,
|
||||||
'count': count,
|
'count': count,
|
||||||
@@ -61,9 +69,14 @@ class PerformancePlatformClient:
|
|||||||
headers=headers
|
headers=headers
|
||||||
)
|
)
|
||||||
|
|
||||||
if resp.status_code != 200:
|
if resp.status_code == 200:
|
||||||
|
current_app.logger.info(
|
||||||
|
"Updated performance platform successfully with payload {}".format(json.dumps(payload))
|
||||||
|
)
|
||||||
|
else:
|
||||||
current_app.logger.error(
|
current_app.logger.error(
|
||||||
"Performance platform update request failed with {} '{}'".format(
|
"Performance platform update request failed for payload with response details: {} '{}'".format(
|
||||||
|
json.dumps(payload),
|
||||||
resp.status_code,
|
resp.status_code,
|
||||||
resp.json())
|
resp.json())
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ def client(mocker):
|
|||||||
client = PerformancePlatformClient()
|
client = PerformancePlatformClient()
|
||||||
current_app = mocker.Mock(config={
|
current_app = mocker.Mock(config={
|
||||||
'PERFORMANCE_PLATFORM_ENABLED': True,
|
'PERFORMANCE_PLATFORM_ENABLED': True,
|
||||||
'PERFORMANCE_PLATFORM_URL': 'performance-platform-url',
|
'PERFORMANCE_PLATFORM_URL': 'https://performance-platform-url/',
|
||||||
'PERFORMANCE_PLATFORM_TOKEN': 'token'
|
'PERFORMANCE_PLATFORM_TOKEN': 'token'
|
||||||
})
|
})
|
||||||
client.init_app(current_app)
|
client.init_app(current_app)
|
||||||
|
|||||||
Reference in New Issue
Block a user