Skip to content

Commit

Permalink
Use Scala 3 LTS
Browse files Browse the repository at this point in the history
  • Loading branch information
fthomas committed Jan 5, 2025
1 parent 6db7dfb commit 2a95e19
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 23 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ val moduleCrossPlatformMatrix: Map[String, List[Platform]] = Map(
)

val Scala213 = "2.13.15"
val Scala3 = "3.6.2"
val Scala3 = "3.3.4"

/// sbt-typelevel configuration

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package org.scalasteward.core.application
import cats.effect._
import cats.effect.implicits._
import cats.syntax.all._
import eu.timepit.refined.auto._
import org.http4s.Uri
import org.http4s.client.Client
import org.http4s.headers.`User-Agent`
Expand Down Expand Up @@ -94,7 +93,7 @@ object Context {
userAgent <- Resource.eval(F.fromEither(`User-Agent`.parse(1)(userAgentString)))
middleware = ClientConfiguration
.setUserAgent[F](userAgent)
.andThen(ClientConfiguration.retryAfter[F](maxAttempts = 5))
.andThen(ClientConfiguration.retryAfter[F]())
defaultClient <- ClientConfiguration.build(
ClientConfiguration.BuilderMiddleware.default,
middleware
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package org.scalasteward.core.client

import cats.effect._
import cats.syntax.all._
import eu.timepit.refined.auto._
import eu.timepit.refined.types.numeric.PosInt
import java.net.http.HttpClient
import java.net.http.HttpClient.Builder
Expand Down Expand Up @@ -69,26 +68,27 @@ object ClientConfiguration {
* max number times the HTTP request should be sent useful to avoid unexpected cloud provider
* costs
*/
def retryAfter[F[_]: Temporal](maxAttempts: PosInt = 5): Middleware[F] = { client =>
Client[F] { req =>
def run(attempt: Int = 1): Resource[F, Response[F]] = client
.run(req.putHeaders("X-Attempt" -> attempt.toString))
.flatMap { response =>
val maybeRetried = for {
header <- response.headers.get(ci"Retry-After")
seconds <- header.head.value.toIntOption
if seconds > 0
duration = seconds.seconds
if RetryAfterStatuses.contains(response.status.code)
if attempt < maxAttempts.value
} yield Resource
.eval(response.as[Unit].voidError *> Temporal[F].sleep(duration))
.flatMap(_ => run(attempt + 1))
maybeRetried.getOrElse(Resource.pure(response))
}
def retryAfter[F[_]: Temporal](maxAttempts: PosInt = PosInt.unsafeFrom(5)): Middleware[F] = {
client =>
Client[F] { req =>
def run(attempt: Int = 1): Resource[F, Response[F]] = client
.run(req.putHeaders("X-Attempt" -> attempt.toString))
.flatMap { response =>
val maybeRetried = for {
header <- response.headers.get(ci"Retry-After")
seconds <- header.head.value.toIntOption
if seconds > 0
duration = seconds.seconds
if RetryAfterStatuses.contains(response.status.code)
if attempt < maxAttempts.value
} yield Resource
.eval(response.as[Unit].voidError *> Temporal[F].sleep(duration))
.flatMap(_ => run(attempt + 1))
maybeRetried.getOrElse(Resource.pure(response))
}

run()
}
run()
}
}

def disableFollowRedirect: BuilderMiddleware = _.followRedirects(HttpClient.Redirect.NEVER)
Expand Down

0 comments on commit 2a95e19

Please sign in to comment.