mirror of
https://github.com/GSA/notifications-api.git
synced 2026-01-31 23:26:23 -05:00
Merge pull request #3293 from alphagov/site-b-link-test-178738544
Trigger separate link test for failover lambda
This commit is contained in:
@@ -1,10 +1,8 @@
|
||||
import uuid
|
||||
from datetime import datetime
|
||||
|
||||
from flask import current_app
|
||||
from sqlalchemy.schema import Sequence
|
||||
|
||||
from app import cbc_proxy_client, db, notify_celery, zendesk_client
|
||||
from app import cbc_proxy_client, notify_celery, zendesk_client
|
||||
from app.clients.cbc_proxy import CBCProxyRetryableException
|
||||
from app.config import QueueNames
|
||||
from app.dao.broadcast_message_dao import (
|
||||
@@ -251,12 +249,4 @@ def send_broadcast_provider_message(self, broadcast_event_id, provider):
|
||||
|
||||
@notify_celery.task(name='trigger-link-test')
|
||||
def trigger_link_test(provider):
|
||||
identifier = str(uuid.uuid4())
|
||||
formatted_seq_number = None
|
||||
if provider == BroadcastProvider.VODAFONE:
|
||||
sequence = Sequence('broadcast_provider_message_number_seq')
|
||||
sequential_number = db.session.connection().execute(sequence)
|
||||
formatted_seq_number = format_sequential_number(sequential_number)
|
||||
message = f"Sending a link test to CBC proxy for provider {provider}. Identifier in payload is {identifier}"
|
||||
current_app.logger.info(message)
|
||||
cbc_proxy_client.get_proxy(provider).send_link_test(identifier, formatted_seq_number)
|
||||
cbc_proxy_client.get_proxy(provider).send_link_test()
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
import json
|
||||
import uuid
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
import boto3
|
||||
import botocore
|
||||
from flask import current_app
|
||||
from notifications_utils.template import non_gsm_characters
|
||||
from sqlalchemy.schema import Sequence
|
||||
|
||||
from app.config import BroadcastProvider
|
||||
from app.utils import DATETIME_FORMAT, format_sequential_number
|
||||
@@ -76,12 +78,14 @@ class CBCProxyClientBase(ABC):
|
||||
def __init__(self, lambda_client):
|
||||
self._lambda_client = lambda_client
|
||||
|
||||
def send_link_test(
|
||||
def send_link_test(self):
|
||||
self._send_link_test(self.lambda_name)
|
||||
self._send_link_test(self.failover_lambda_name)
|
||||
|
||||
def _send_link_test(
|
||||
self,
|
||||
identifier,
|
||||
sequential_number
|
||||
):
|
||||
pass
|
||||
lambda_name,
|
||||
): pass
|
||||
|
||||
def create_and_send_broadcast(
|
||||
self, identifier, headline, description, areas, sent, expires, channel, message_number=None
|
||||
@@ -118,6 +122,10 @@ class CBCProxyClientBase(ABC):
|
||||
def _invoke_lambda(self, lambda_name, payload):
|
||||
payload_bytes = bytes(json.dumps(payload), encoding='utf8')
|
||||
try:
|
||||
current_app.logger.info(
|
||||
f"Calling lambda {lambda_name} with payload {str(payload)[:1000]}"
|
||||
)
|
||||
|
||||
result = self._lambda_client.invoke(
|
||||
FunctionName=lambda_name,
|
||||
InvocationType='RequestResponse',
|
||||
@@ -155,10 +163,9 @@ class CBCProxyOne2ManyClient(CBCProxyClientBase):
|
||||
LANGUAGE_ENGLISH = 'en-GB'
|
||||
LANGUAGE_WELSH = 'cy-GB'
|
||||
|
||||
def send_link_test(
|
||||
def _send_link_test(
|
||||
self,
|
||||
identifier,
|
||||
sequential_number=None,
|
||||
lambda_name,
|
||||
):
|
||||
"""
|
||||
link test - open up a connection to a specific provider, and send them an xml payload with a <msgType> of
|
||||
@@ -166,11 +173,11 @@ class CBCProxyOne2ManyClient(CBCProxyClientBase):
|
||||
"""
|
||||
payload = {
|
||||
'message_type': 'test',
|
||||
'identifier': identifier,
|
||||
'identifier': str(uuid.uuid4()),
|
||||
'message_format': 'cap'
|
||||
}
|
||||
|
||||
self._invoke_lambda_with_failover(payload=payload)
|
||||
self._invoke_lambda(lambda_name=lambda_name, payload=payload)
|
||||
|
||||
def create_and_send_broadcast(
|
||||
self, identifier, headline, description, areas, sent, expires, channel, message_number=None
|
||||
@@ -231,23 +238,27 @@ class CBCProxyVodafone(CBCProxyClientBase):
|
||||
LANGUAGE_ENGLISH = 'English'
|
||||
LANGUAGE_WELSH = 'Welsh'
|
||||
|
||||
def send_link_test(
|
||||
def _send_link_test(
|
||||
self,
|
||||
identifier,
|
||||
sequential_number,
|
||||
lambda_name,
|
||||
):
|
||||
"""
|
||||
link test - open up a connection to a specific provider, and send them an xml payload with a <msgType> of
|
||||
test.
|
||||
"""
|
||||
from app import db
|
||||
sequence = Sequence('broadcast_provider_message_number_seq')
|
||||
sequential_number = db.session.connection().execute(sequence)
|
||||
formatted_seq_number = format_sequential_number(sequential_number)
|
||||
|
||||
payload = {
|
||||
'message_type': 'test',
|
||||
'identifier': identifier,
|
||||
'message_number': sequential_number,
|
||||
'identifier': str(uuid.uuid4()),
|
||||
'message_number': formatted_seq_number,
|
||||
'message_format': 'ibag'
|
||||
}
|
||||
|
||||
self._invoke_lambda_with_failover(payload=payload)
|
||||
self._invoke_lambda(lambda_name=lambda_name, payload=payload)
|
||||
|
||||
def create_and_send_broadcast(
|
||||
self, identifier, message_number, headline, description, areas, sent, expires, channel
|
||||
|
||||
Reference in New Issue
Block a user