mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-18 21:48:49 -04:00
send messages to multiple providers
at the moment only EE is enabled (this is set in app.config, but also, only EE have a function defined for them so even if another provider was enabled without changing the dict in cbc_proxy.py we won't trigger anything). this commit just adds wrapper tasks that check what providers are enabled, and invokes the send function for each provider. The send function doesn't currently distinguish between providers for now - as we only have EE set up. in the future we'll want to separate the cbc_proxy_client into separate clients for separate providers. Different providers have different lambda functions, and have different requirements. For example, we know that the two different CBC software solutions handle references to previous messages differently.
This commit is contained in:
@@ -1,15 +1,29 @@
|
||||
import uuid
|
||||
|
||||
from flask import current_app
|
||||
from notifications_utils.statsd_decorators import statsd
|
||||
|
||||
from app import cbc_proxy_client, notify_celery
|
||||
|
||||
from app.models import BroadcastEventMessageType
|
||||
from app.config import QueueNames
|
||||
from app.models import BroadcastEventMessageType, BroadcastProvider
|
||||
from app.dao.broadcast_message_dao import dao_get_broadcast_event_by_id
|
||||
|
||||
|
||||
@notify_celery.task(name="send-broadcast-event")
|
||||
@statsd(namespace="tasks")
|
||||
def send_broadcast_event(broadcast_event_id):
|
||||
for provider in BroadcastProvider.PROVIDERS:
|
||||
# TODO: Decide whether to send to each provider based on platform admin, service level settings, broadcast
|
||||
# level settings, etc.
|
||||
send_broadcast_provider_message.apply_async(
|
||||
kwargs={'broadcast_event_id': broadcast_event_id, 'provider': provider},
|
||||
queue=QueueNames.NOTIFY
|
||||
)
|
||||
|
||||
|
||||
@notify_celery.task(name="send-broadcast-provider-message")
|
||||
@statsd(namespace="tasks")
|
||||
def send_broadcast_provider_message(broadcast_event_id, provider):
|
||||
broadcast_event = dao_get_broadcast_event_by_id(broadcast_event_id)
|
||||
|
||||
current_app.logger.info(
|
||||
@@ -52,3 +66,24 @@ def send_broadcast_event(broadcast_event_id):
|
||||
sent=broadcast_event.sent_at_as_cap_datetime_string,
|
||||
expires=broadcast_event.transmitted_finishes_at_as_cap_datetime_string,
|
||||
)
|
||||
|
||||
|
||||
@notify_celery.task(name='trigger-link-test')
|
||||
def trigger_link_test(provider):
|
||||
"""
|
||||
Currently we only have one hardcoded CBC Proxy, which corresponds to one
|
||||
CBC, and so currently we do not specify the CBC Proxy name
|
||||
|
||||
In future we will have multiple CBC proxies, each proxy corresponding to
|
||||
one MNO's CBC
|
||||
|
||||
This task should invoke other tasks which do the actual link tests, eg:
|
||||
for cbc_name in app.config.ENABLED_CBCS:
|
||||
send_link_test_for_cbc(cbc_name)
|
||||
|
||||
Alternatively this task could be configured to be a Celery group
|
||||
"""
|
||||
identifier = str(uuid.uuid4())
|
||||
message = f"Sending a link test to CBC proxy for provider {provider} with ID {identifier}"
|
||||
current_app.logger.info(message)
|
||||
cbc_proxy_client.send_link_test(identifier)
|
||||
|
||||
Reference in New Issue
Block a user