def sendNotification()

in notificationworkerlambda/src/main/scala/com/gu/notifications/worker/delivery/fcm/FcmClient.scala [58:83]


  def sendNotification(notificationId: UUID, token: String, payload: Payload, dryRun: Boolean)
    (onAPICallComplete: Either[DeliveryException, Success] => Unit)
    (implicit executionContext: ExecutionContextExecutor) = {

    val message = Message
      .builder
      .setToken(token)
      .setAndroidConfig(payload.androidConfig)
      .build

    if (dryRun) { // Firebase has a dry run mode but in order to get the same behavior for both APNS and Firebase we don't send the request
      onAPICallComplete(Right(FcmDeliverySuccess(token, "dryrun", Instant.now(), dryRun = true)))
    } else {
      import FirebaseHelpers._
      val start = Instant.now
      fcmTransport.sendAsync(token, payload, dryRun)
        .onComplete { response =>
          val requestCompletionTime = Instant.now
          logger.info(Map(
            "worker.individualRequestLatency" -> Duration.between(start, requestCompletionTime).toMillis,
            "notificationId" -> notificationId,
          ), s"Individual send request completed - ${this.toString()}")
          onAPICallComplete(parseSendResponse(notificationId, token, response, requestCompletionTime))
        }
    }
  }