{"id":15627933,"url":"https://github.com/sunng87/diehard","last_synced_at":"2025-05-15T15:03:40.923Z","repository":{"id":9472349,"uuid":"61934109","full_name":"sunng87/diehard","owner":"sunng87","description":"Clojure resilience library for flexible retry, circuit breaker and rate limiter","archived":false,"fork":false,"pushed_at":"2024-10-09T21:40:19.000Z","size":434,"stargazers_count":338,"open_issues_count":6,"forks_count":27,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-04-04T11:47:23.138Z","etag":null,"topics":["bulkhead","circuit-breaker","clojure","rate-limiter","resilience","retry-library"],"latest_commit_sha":null,"homepage":"","language":"Clojure","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"epl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sunng87.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["sunng87"],"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":"Sunng","issuehunt":null,"otechie":null,"lfx_crowdfunding":null,"custom":null}},"created_at":"2016-06-25T08:28:00.000Z","updated_at":"2025-02-27T12:27:08.000Z","dependencies_parsed_at":"2023-10-02T14:45:39.491Z","dependency_job_id":"079c326e-e718-4c87-8b81-9d377e2e5efe","html_url":"https://github.com/sunng87/diehard","commit_stats":{"total_commits":372,"total_committers":20,"mean_commits":18.6,"dds":0.09677419354838712,"last_synced_commit":"1af9762264acf2efbae29bf9578efd420ec32549"},"previous_names":[],"tags_count":50,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sunng87%2Fdiehard","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sunng87%2Fdiehard/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sunng87%2Fdiehard/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sunng87%2Fdiehard/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sunng87","download_url":"https://codeload.github.com/sunng87/diehard/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248449223,"owners_count":21105450,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bulkhead","circuit-breaker","clojure","rate-limiter","resilience","retry-library"],"created_at":"2024-10-03T10:20:03.780Z","updated_at":"2025-04-11T17:28:41.278Z","avatar_url":"https://github.com/sunng87.png","language":"Clojure","funding_links":["https://github.com/sponsors/sunng87","https://liberapay.com/Sunng","https://liberapay.com/Sunng/donate"],"categories":[],"sub_categories":[],"readme":"# diehard\n\n[![CI](https://github.com/sunng87/diehard/actions/workflows/clojure.yml/badge.svg)](https://github.com/sunng87/diehard/actions/workflows/clojure.yml)\n[![Clojars](https://img.shields.io/clojars/v/diehard.svg?maxAge=2592000)](https://clojars.org/diehard)\n[![license](https://img.shields.io/github/license/sunng87/diehard.svg?maxAge=2592000)]()\n[![Donate](https://img.shields.io/badge/donate-liberapay-yellow.svg)](https://liberapay.com/Sunng/donate)\n\n\nClojure library to provide safety guard to your application.\nSome of the functionality is wrapper over\n[Failsafe](https://github.com/jhalterman/failsafe).\n\nNote that from 0.7 diehard uses Clojure 1.9 and spec.alpha for\nconfiguration validation. Clojure 1.8 users could stick with diehard\n`0.6.0`.\n\n## Usage\n\nA quick example for diehard usage.\n\n### Retry block\n\nA retry block will re-execute inner forms when retry criteria matches.\n\n```clojure\n(require '[diehard.core :as dh])\n(dh/with-retry {:retry-on TimeoutException\n                :max-retries 3}\n  (fetch-data-from-the-moon))\n```\n\n### Circuit breaker\n\nA circuit breaker will track the execution of inner block and skip\nexecution if the open condition triggered.\n\n```clojure\n(require '[diehard.core :as dh])\n\n(dh/defcircuitbreaker my-cb {:failure-threshold-ratio [8 10]\n                          :delay-ms 1000})\n\n(dh/with-circuit-breaker my-cb\n  (fetch-data-from-the-moon))\n```\n\n### Rate limiter\n\nA rate limiter protects your code block to run limited times per\nsecond. It will block or throw exception depends on your\nconfiguration. (:rate is a floating point number, and can be less than 1.0. \nExample: 0.5 is once every two seconds.)\n\n```clojure\n(require '[diehard.core :as dh])\n\n(dh/defratelimiter my-rl {:rate 100})\n\n(dh/with-rate-limiter my-rl\n  (send-people-to-the-moon))\n```\n\n### Bulkhead\n\nBulkhead allows you to limit concurrent execution on a code block.\n\n```clojure\n(require '[diehard.core :as dh])\n\n;; at most 10 threads can run the code block concurrently\n(dh/defbulkhead my-bh {:concurrency 10})\n\n(dh/with-bulkhead my-bh\n  (send-people-to-the-moon))\n```\n\n### Timeout\n\nTimeouts allow you to fail an execution with `TimeoutExceededException` if it takes too long to complete\n\n```clojure\n(require '[diehard.core :as dh])\n\n(dh/with-timeout {:timeout-ms 5000\n                  :interrupt? true}\n  (fly-me-to-the-moon))\n```\n\n## Examples\n### Retry block\n\n```clojure\n(dh/with-retry {:retry-on          Exception\n                :max-retries       3\n                :on-retry          (fn [val ex] (prn \"retrying...\"))\n                :on-failure        (fn [_ _] (prn \"failed...\"))\n                :on-failed-attempt (fn [_ _] (prn \"failed attempt\"))\n                :on-success        (fn [_] (prn \"did it! success!\"))}\n               (throw (ex-info \"not good\" {:not \"good\"})))\n```\n\noutput:\n```\n\"failed attempt\"\n\"retrying...\"\n\"failed attempt\"\n\"retrying...\"\n\"failed attempt\"\n\"retrying...\"\n\"failed attempt\"\n\"failed...\"\nExecution error (ExceptionInfo) at main.user$eval27430$reify__27441/get (form-init6791465293873302710.clj:7).\nnot good\n```\n\n## Docs\n\nMore options can be found in the documentation\n[from cljdoc](https://cljdoc.org/d/diehard/diehard/).\n\n## Build\n\nThis project uses deps.edn and build.edn for dependency management. To build the\nproject, run\n\n```shell\nclojure -T:build install\n```\n\n## License\n\nCopyright © 2016-2023 Ning Sun\n\nDistributed under the Eclipse Public License either version 1.0 or (at\nyour option) any later version.\n\n## Donation\n\nI'm now accepting donation on [liberapay](https://liberapay.com/Sunng/donate),\nif you find my work helpful and want to keep it going.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsunng87%2Fdiehard","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsunng87%2Fdiehard","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsunng87%2Fdiehard/lists"}