Giter VIP home page Giter VIP logo

retry4k's Introduction

retry4k

Retry4k is resilience and fault tolerance library written in kotlin.

Kotlin version badge License CircleCI codecov

Usage

//retry maximum of 3 times if nullpointer exception occurred
 RetryOptions.Builder<String>().maxAttempt(3).retryOnException(NullPointerException::class.java).build()
//retry maximum of 3 times if action returns returns result with string retryme and wait for 1000ms before every retry

 val retryOnResult: (String) -> Boolean = {result -> result == "retryme"}

 RetryOptions.Builder<String>().maxAttempt(3).retryOnResult(retryOnResult).waitDuration(1000).build()
//Don't retry if the exception thrown by action is IllegalArgumentException. 

 val retryOnResult: (String) -> Boolean = {result -> result == "retryme"}

 RetryOptions.Builder<String>().waitDuration(1000).maxAttempt(5).retryOnException(NullPointerException::class.java).retryOnResult(retryOnResult).ignoreOnException(IllegalArgumentException::class.java).build()
//Do some action before every retry attempt and after completion of either successfull or failure execution of action. 

 val beforeRetry:(Throwable?, String?, Int) -> Unit = { throwable,result, cuurentAttempt -> println("attempting for $cuurentAttempt time)}
 
 val onCompleted:(Throwable?, String?, Int) -> Unit = { throwable,result, cuurentAttempt -> println("completed after $cuurentAttempt times)}
 
  val retryStrategy = RetryOptions.Builder<String>().maxAttempt(5).retryOnException(NullPointerException::class.java)
                 .doOnBeforeRetry(beforeRetry).doOnCompleted(onCompleted).build()

Execution

    val retryOption = RetryOptions.Builder<String>().maxAttempt(3).retryOnException(NullPointerException::class.java).build()
    val retryExecutor = RetryExecutor(retryOption)
    retryExecutor.execute { business logic }

TODO:

  • allow option to define custom wait strategy
  • implement multiple backOff strategy (exponential, Jitter etc)
  • publish as maven artifact
  • pluggable metric publisher (dropwizard, micrometer)
  • DSL based retryOptions

retry4k's People

Contributors

thiyagu06 avatar

Stargazers

 avatar

Watchers

 avatar

Forkers

morristech

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.