scala-retry


License

License

Categories

Categories

Scala Languages
GroupId

GroupId

com.github.takezoe
ArtifactId

ArtifactId

scala-retry_2.13
Last Version

Last Version

0.0.6
Release Date

Release Date

Type

Type

jar
Description

Description

scala-retry
scala-retry
Project URL

Project URL

https://github.com/takezoe/scala-retry
Project Organization

Project Organization

com.github.takezoe
Source Code Management

Source Code Management

https://github.com/takezoe/scala-retry

Download scala-retry_2.13

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.takezoe/scala-retry_2.13/ -->
<dependency>
    <groupId>com.github.takezoe</groupId>
    <artifactId>scala-retry_2.13</artifactId>
    <version>0.0.6</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.takezoe/scala-retry_2.13/
implementation 'com.github.takezoe:scala-retry_2.13:0.0.6'
// https://jarcasting.com/artifacts/com.github.takezoe/scala-retry_2.13/
implementation ("com.github.takezoe:scala-retry_2.13:0.0.6")
'com.github.takezoe:scala-retry_2.13:jar:0.0.6'
<dependency org="com.github.takezoe" name="scala-retry_2.13" rev="0.0.6">
  <artifact name="scala-retry_2.13" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.takezoe', module='scala-retry_2.13', version='0.0.6')
)
libraryDependencies += "com.github.takezoe" % "scala-retry_2.13" % "0.0.6"
[com.github.takezoe/scala-retry_2.13 "0.0.6"]

Dependencies

compile (1)

Group / Artifact Type Version
org.scala-lang : scala-library jar 2.13.4

test (1)

Group / Artifact Type Version
org.scalatest : scalatest_2.13 jar 3.0.8

Project Modules

There are no modules declared in this project.

scala-retry CI Maven Central

Offers simple retry functionality for Scala.

libraryDependencies += "com.github.takezoe" %% "scala-retry" % "0.0.6"

Retry synchronously

retry runs and retries a given block on the current thread. If the block is successful, it returns a value. Otherwise, it throws an exception. Note that the current thread is blocked during retrying.

import com.github.takezoe.retry._
import scala.concurrent.duration._

implicit val policy = RetryPolicy(
  maxAttempts = 3, 
  retryDuration = 1.second, 
  backOff = ExponentialBackOff, // default is FixedBackOff
  jitter = 1.second // default is no jitter
)

val result: String = retry {
  // something to retry
  "Hello World!"
}

Retry Future

retryFuture takes Future (a block which generates Future, more precisely) instead of a function. Note that it requires ExecutionContext additionally.

import com.github.takezoe.retry._
import scala.concurrent.duration._
import scala.concurrent.Future
import scala.concurrent.ExecutionContext.Implicits.global

implicit val rm = new RetryManager()
implicit val policy = RetryPolicy(
  maxAttempts = 3, 
  retryDuration = 1.second, 
  backOff = ExponentialBackOff
)

val future: Future[String] = retryFuture {
  Future {
    // something to retry
    "Hello World!"
  }
}

CircuitBreaker

import com.github.takezoe.retry._
import scala.concurrent.duration._

implicit val policy = CircuitBreakerPolicy(
  failureThreshold = 3,
  successThreshold = 3,
  retryDuration = 1.minute
)

val result: String = circuitBreaker {
  // Something can be failed
  "Hello World!"
}

Versions

Version
0.0.6
0.0.5
0.0.4
0.0.3