in notification/app/notification/controllers/Main.scala [68:109]
def pushTopics: Action[Notification] = authAction.async(parse.json[Notification]) { request =>
val notificationReceivedTime = Instant.now
val notification = request.body
val topics = notification.topic
val MaxTopics = 20
(topics.size match {
case 0 => Future.successful(BadRequest("Empty topic list"))
case a: Int if a > MaxTopics => Future.successful(BadRequest(s"Too many topics, maximum: $MaxTopics"))
case _ if !topics.forall{topic => request.isPermittedTopicType(topic.`type`)} =>
Future.successful(Unauthorized(s"This API key is not valid for ${topics.filterNot(topic => request.isPermittedTopicType(topic.`type`))}."))
case _ => pushWithDuplicateProtection(notification, notificationReceivedTime).map(send => {
val durationMillis = Duration.between(notificationReceivedTime, Instant.now).toMillis
if (notification.`type` == BreakingNews && !notification.dryRun.contains(true)) {
logger.info("Sending SLO tracking message to SQS queue")
sloTrackingSender.sendTrackingMessage(notification.id)
}
logger.info(
Map(
"notificationId" -> notification.id,
"notificationType" -> notification.`type`.toString,
"notificationTitle" -> notification.title.getOrElse("Unknown"),
"notificationApp.notificationProcessingTime" -> durationMillis,
"notificationApp.notificationReceivedTime.millis" -> notificationReceivedTime.toEpochMilli,
"notificationApp.notificationReceivedTime.string" -> notificationReceivedTime.toString,
),
s"Spent $durationMillis milliseconds processing notification ${notification.id}")
metrics.send(MetricDataPoint(name = "NotificationAppProcessingTime", value = durationMillis.toDouble, unit = StandardUnit.Milliseconds))
notification.`type` match {
case BreakingNews => metrics.send(MetricDataPoint(name = "BreakingNewsNotificationCount", value = 1, unit = StandardUnit.Count))
case _ => {}
}
send
})
}) recoverWith {
case NonFatal(exception) => {
logger.warn(s"Pushing notification failed: $notification", exception)
Future.successful(InternalServerError)
}
}
}