Retry
object Retry
- Source:
- Retry.scala
Value members
Concrete methods
h.retrymatch{
caseLeft(d)=>
Instant.now().until(d.toInstant,ChronoUnit.SECONDS)
caseRight(secs)=>
(secs:Long)
})).getOrElse[Long](0L)
valsleepDuration:FiniteDuration=DurationLong(headerDuration).seconds.max(duration)
catsSyntaxFlatMapOps[F,Unit](F.sleep(sleepDuration))(F).>>[Response[F]](retryLoop(req,attempts.+(1),hotswap))(F)
}
defretryLoop(`req₂`:Request[F],`attempts₂`:Int,`hotswap₂`:Hotswap[F,Either[Throwable,Response[F]]]):F[Response[F]]=catsSyntaxApply[F,Unit](`hotswap₂`.clear)(F).*>[Response[F]](toFlatMapOps[F,Either[Throwable,Response[F]]](`hotswap₂`.swap(client.run(`req₂`.withAttribute[Int](AttemptCountKey,`attempts₂`)).map[Response[F]](((_$3:Response[F])=>_$3.withAttribute[Int](AttemptCountKey,`attempts₂`))).attempt[Throwable](F)))(F).flatMap[Response[F]](((x$1:Either[Throwable,Response[F]])=>x$1match{
caseRight(response)=>
policy.apply(`req₂`,Right.apply[Nothing,Response[F]](response),`attempts₂`)match{
caseSome(duration)=>
if(logRetries)logger.info(_root_.scala.StringContext.apply("Request","hasfailedonattempt#","withreason",".Retryingafter",".").s(showRequest(`req₂`,redactHeaderWhen),`attempts₂`,response.status,`duration₂`))else()
nextAttempt(`req₂`,`attempts₂`,`duration₂`,response.headers.get[Retry-After](singleHeaders[Retry-After](headerInstance)),`hotswap₂`)
caseNone=>
F.pure[Response[F]](response)
}
caseLeft(e)=>
policy.apply(`req₂`,Left.apply[Throwable,Nothing](e),`attempts₂`)match{
caseSome(duration)=>
if(logRetries)logger.info(e)(_root_.scala.StringContext.apply("Requestthrewanexceptiononattempt#",".Retryingafter","").s(`attempts₂`,`duration₃`))else()
nextAttempt(`req₂`,`attempts₂`,`duration₃`,None,`hotswap₂`)
caseNone=>
if(logRetries)logger.info(e)(_root_.scala.StringContext.apply("Request","threwanexceptiononattempt#",".Givingup.").s(showRequest(`req₂`,redactHeaderWhen),`attempts₂`))else()
F.raiseError[Response[F]](e)
}
})))
Client.apply[F](((`req₃`:Request[F])=>Hotswap.create[F,Either[Throwable,Response[F]]](F).flatMap[Response[F]](((`hotswap₃`:Hotswap[F,Either[Throwable,Response[F]]])=>Resource.eval[F,Response[F]](retryLoop(`req₃`,1,`hotswap₃`))))))(F)
}" class="documentableAnchor">
def h.retrymatch{
caseLeft(d)=>
Instant.now().until(d.toInstant,ChronoUnit.SECONDS)
caseRight(secs)=>
(secs:Long)
})).getOrElse[Long](0L)
valsleepDuration:FiniteDuration=DurationLong(headerDuration).seconds.max(duration)
catsSyntaxFlatMapOps[F,Unit](F.sleep(sleepDuration))(F).>>[Response[F]](retryLoop(req,attempts.+(1),hotswap))(F)
}
defretryLoop(`req₂`:Request[F],`attempts₂`:Int,`hotswap₂`:Hotswap[F,Either[Throwable,Response[F]]]):F[Response[F]]=catsSyntaxApply[F,Unit](`hotswap₂`.clear)(F).*>[Response[F]](toFlatMapOps[F,Either[Throwable,Response[F]]](`hotswap₂`.swap(client.run(`req₂`.withAttribute[Int](AttemptCountKey,`attempts₂`)).map[Response[F]](((_$3:Response[F])=>_$3.withAttribute[Int](AttemptCountKey,`attempts₂`))).attempt[Throwable](F)))(F).flatMap[Response[F]](((x$1:Either[Throwable,Response[F]])=>x$1match{
caseRight(response)=>
policy.apply(`req₂`,Right.apply[Nothing,Response[F]](response),`attempts₂`)match{
caseSome(duration)=>
if(logRetries)logger.info(_root_.scala.StringContext.apply("Request","hasfailedonattempt#","withreason",".Retryingafter",".").s(showRequest(`req₂`,redactHeaderWhen),`attempts₂`,response.status,`duration₂`))else()
nextAttempt(`req₂`,`attempts₂`,`duration₂`,response.headers.get[Retry-After](singleHeaders[Retry-After](headerInstance)),`hotswap₂`)
caseNone=>
F.pure[Response[F]](response)
}
caseLeft(e)=>
policy.apply(`req₂`,Left.apply[Throwable,Nothing](e),`attempts₂`)match{
caseSome(duration)=>
if(logRetries)logger.info(e)(_root_.scala.StringContext.apply("Requestthrewanexceptiononattempt#",".Retryingafter","").s(`attempts₂`,`duration₃`))else()
nextAttempt(`req₂`,`attempts₂`,`duration₃`,None,`hotswap₂`)
caseNone=>
if(logRetries)logger.info(e)(_root_.scala.StringContext.apply("Request","threwanexceptiononattempt#",".Givingup.").s(showRequest(`req₂`,redactHeaderWhen),`attempts₂`))else()
F.raiseError[Response[F]](e)
}
})))
Client.apply[F](((`req₃`:Request[F])=>Hotswap.create[F,Either[Throwable,Response[F]]](F).flatMap[Response[F]](((`hotswap₃`:Hotswap[F,Either[Throwable,Response[F]]])=>Resource.eval[F,Response[F]](retryLoop(`req₃`,1,`hotswap₃`))))))(F)
}" class="documentableName ">create[F[_]](policy: () => F, redactHeaderWhen: CIString => Boolean, logRetries: Boolean)(client: Client[F])(implicit F: Temporal[F]): Client[F]
- Source:
- Retry.scala
Concrete fields
This key tracks the attempt count, the retry middleware starts the very first request with 1 as the first request, even with no retries (aka the first attempt). If one wants to monitor retries explicitly and not the attempts one may want to subtract the value of this key by 1.
This key tracks the attempt count, the retry middleware starts the very first request with 1 as the first request, even with no retries (aka the first attempt). If one wants to monitor retries explicitly and not the attempts one may want to subtract the value of this key by 1.
- Source:
- Retry.scala