GithubHelp home page GithubHelp logo

resilience4clj / resilience4clj-retry Goto Github PK

View Code? Open in Web Editor NEW
23.0 3.0 2.0 23 KB

Resilience4Clj Retry lets you decorate a function call with a specified number of retry attempts.

License: MIT License

Clojure 100.00%
resilience retry circuit-breaker cache metrics clojure

resilience4clj-retry's Issues

Fix `retry/create` example

Thanks for the sweet lib!

The example of how to create a retry with configuration doesn't run:

(def retry (r/create {:max-attempts 10
                      :wait-duration 300}))
clojure.lang.PersistentArrayMap is in unnamed module of loader 'app'; java.lang.String is in module java.base of loader 'bootstrap')

This example requires a name string, e.g.

(def retry "my-retry" (r/create {:max-attempts 10
                      :wait-duration 300}))
=>
#object[io.github.resilience4j.retry.internal.RetryImpl
        0x4941ec8f
        "io.github.resilience4j.retry.internal.RetryImpl@4941ec8f"]

Fixing this would help others get started with the library, as I ran into this issue myself trying to get set up.

Not retrying when Exception is thrown

I have existing functions that I'm attempting to decorate as retriable, but I'm noticing that retry is not triggered when java.lang.Exception is thrown, I'm not sure if this is an issue with the upstream dependency, but I can repro it with this code:

(require '[resilience4clj-retry.core :as r])
(def retry (r/create "test-retry"))
(r/listen-event retry
                :RETRY
                (fn [_] (println "retrying...")))

;; 1. Exception
(def retriable-fn
  (r/decorate
    (fn [] (throw (Exception. "not good")))
    retry))

(retriable-fn)
;; Execution error at retry/fn (retry.clj:4).
;; not good

;; 2. ex-info
(def retriable-fn
  (r/decorate
    (fn [] (throw (ex-info "not good" {})))
    retry))

(retriable-fn)
;; retrying...
;; retrying...
;; Execution error (ExceptionInfo) at retry/fn (retry.clj:3).
;; not good

;; 3. Exception caught and re-thrown as ex-info
(def retriable-fn
  (r/decorate
    (fn [] (throw (ex-info "not good" {} (Exception. "not good"))))
    retry))

(retriable-fn)
;; retrying...
;; retrying...
;; Execution error at retry/fn (retry.clj:3).
;; not good
  1. Throws java.lang.Exception and retry logic is never executed
  2. Works as expected
  3. Also works, but requires extra layer of try-catch

What am I missing here? Is there a config that I must add to catch java.lang.Exception?

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.