mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-17 10:42:25 -05:00
"areas" and "simple_polygons" in "transmitted_areas" do not have the same length as an example, choosing the area "england" results in a single item in "areas" but many polygons in "simple_polygons" therefore zipping these two together gives a list of areas: * of length 1 * containing only new grimsby which is not what we want as the CBC does not care about the areaDesc field within CAP, we should omit it from the function invocation and delegate the contents of areaDesc to the CBC Proxy implementation Signed-off-by: Toby Lorne <toby.lornewelch-richards@digital.cabinet-office.gov.uk> Co-authored-by: Richard <richard.baker@digital.cabinet-office.gov.uk> Co-authored-by: David <david.mcdonald@digital.cabinet-office.gov.uk>
49 lines
1.8 KiB
Python
49 lines
1.8 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 = [
|
|
{"polygon": polygon}
|
|
for polygon in 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(),
|
|
)
|