Files
notifications-api/app/celery/broadcast_message_tasks.py
Toby Lorne fdacb2e0d7 broadcasts: remove references to cbc stub
We are phasing out our cbc-proxy stub which displayed CAP XML messages

We are in the process of testing with real CBCs, so maintaining our own
stub is not useful

This commit
* removes the HTTP POST requests to the CBC proxy
* writes up the update/cancel methods of the cbc_client (not impl)

Signed-off-by: Toby Lorne <toby.lornewelch-richards@digital.cabinet-office.gov.uk>
2020-10-26 10:23:49 +00:00

52 lines
1.9 KiB
Python

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.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):
broadcast_event = dao_get_broadcast_event_by_id(broadcast_event_id)
current_app.logger.info(
f'invoking cbc proxy to send '
f'broadcast_event {broadcast_event.reference} '
f'msgType {broadcast_event.message_type}'
)
areas = [
{"description": desc, "polygon": polygon}
for desc, polygon in zip(
broadcast_event.transmitted_areas["areas"],
broadcast_event.transmitted_areas["simple_polygons"],
)
]
if broadcast_event.message_type == BroadcastEventMessageType.ALERT:
cbc_proxy_client.create_and_send_broadcast(
identifier=str(broadcast_event.id),
headline="GOV.UK Notify Broadcast",
description=broadcast_event.transmitted_content['body'],
areas=areas,
)
elif broadcast_event.message_type == BroadcastEventMessageType.UPDATE:
cbc_proxy_client.update_and_send_broadcast(
identifier=str(broadcast_event.id),
headline="GOV.UK Notify Broadcast",
description=broadcast_event.transmitted_content['body'],
areas=areas,
references=broadcast_event.get_earlier_message_references(),
)
elif broadcast_event.message_type == BroadcastEventMessageType.CANCEL:
cbc_proxy_client.cancel_broadcast(
identifier=str(broadcast_event.id),
headline="GOV.UK Notify Broadcast",
description=broadcast_event.transmitted_content['body'],
areas=areas,
references=broadcast_event.get_earlier_message_references(),
)