in src/backend/booking/src/notify-booking/notify.py [0:0]
def notify_booking(payload, booking_reference):
"""Notify whether a booking have been processed successfully
Parameters
----------
payload: dict
Payload to be sent as notification
customerId: string
Unique Customer ID
price: string
Flight price
booking_reference: string
Confirmed booking reference
Returns
-------
dict
notificationId: string
Unique ID confirming notification delivery
Raises
------
BookingNotificationException
Booking Notification Exception including error message upon failure
"""
booking_reference = booking_reference or "most recent booking"
successful_subject = f"Booking confirmation for {booking_reference}"
unsuccessful_subject = f"Unable to process booking for {booking_reference}"
subject = successful_subject if booking_reference else unsuccessful_subject
booking_status = "confirmed" if booking_reference else "cancelled"
try:
logger.debug(
{
"operation": "booking_notification",
"details": {
"customer_id": payload["customerId"],
"booking_price": payload["price"],
"booking_status": booking_status,
},
}
)
ret = sns.publish(
TopicArn=booking_sns_topic,
Message=json.dumps(payload),
Subject=subject,
MessageAttributes={
"Booking.Status": {"DataType": "String", "StringValue": booking_status}
},
)
logger.info({"operation": "booking_notification", "details": ret})
tracer.put_metadata(booking_reference, ret)
return {"notificationId": ret["MessageId"]}
except ClientError as err:
logger.debug({"operation": "booking_notification"})
raise BookingNotificationException(details=err)