private[ml] def sendWithRetries()

in core/src/main/scala/com/microsoft/azure/synapse/ml/io/http/HTTPClients.scala [74:121]


  private[ml] def sendWithRetries(client: CloseableHttpClient,
                                  request: HttpRequestBase,
                                  retriesLeft: Array[Int]): CloseableHttpResponse = {
    val response = client.execute(request)
    val code = response.getStatusLine.getStatusCode
    //scalastyle:off magic.number
    val succeeded = code match {
      case 200 => true
      case 201 => true
      case 202 => true
      case 429 =>
        Option(response.getFirstHeader("Retry-After"))
          .foreach { h =>
            logInfo(s"waiting ${h.getValue} on ${
              request match {
                case p: HttpPost => p.getURI + "   " +
                  Try(IOUtils.toString(p.getEntity.getContent, "UTF-8")).getOrElse("")
                case _ => request.getURI
              }
            }")
            Thread.sleep(h.getValue.toLong * 1000)
          }
        false
      case 400 =>
        true
      case _ =>
        logWarning(s"got error  $code: ${response.getStatusLine.getReasonPhrase} on ${
          request match {
            case p: HttpPost => p.getURI + "   " +
              Try(IOUtils.toString(p.getEntity.getContent, "UTF-8")).getOrElse("")
            case _ => request.getURI
          }
        }")
        false
    }
    //scalastyle:on magic.number
    if (succeeded || retriesLeft.isEmpty) {
      response
    } else {
      response.close()
      Thread.sleep(retriesLeft.head.toLong)
      if (code == 429) { // Do not count rate limiting in number of failures
        sendWithRetries(client, request, retriesLeft)
      } else {
        sendWithRetries(client, request, retriesLeft.tail)
      }
    }
  }