mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-01 15:46:07 -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)
|
||||
encryption.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])
|
||||
|
||||
register_blueprint(application)
|
||||
|
||||
@@ -13,16 +13,24 @@ from app.utils import (
|
||||
|
||||
class PerformancePlatformClient:
|
||||
|
||||
@property
|
||||
def active(self):
|
||||
return self._active
|
||||
|
||||
@active.setter
|
||||
def active(self, value):
|
||||
self._active = value
|
||||
|
||||
def init_app(self, app):
|
||||
self.active = app.config.get('PERFORMANCE_PLATFORM_ENABLED')
|
||||
self._active = app.config.get('PERFORMANCE_PLATFORM_ENABLED')
|
||||
if self.active:
|
||||
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):
|
||||
if self.active:
|
||||
payload = {
|
||||
'_timestamp': date,
|
||||
'_timestamp': str(date),
|
||||
'service': 'govuk-notify',
|
||||
'channel': channel,
|
||||
'count': count,
|
||||
@@ -61,9 +69,14 @@ class PerformancePlatformClient:
|
||||
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(
|
||||
"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.json())
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user