mirror of
https://github.com/cachix/stamina.hs.git
synced 2024-08-16 22:10:34 +03:00
Retrying for humans using Haskell.
.github/workflows | ||
src | ||
test | ||
.envrc | ||
.gitignore | ||
CHANGELOG.md | ||
devenv.lock | ||
devenv.nix | ||
LICENSE | ||
README.lhs | ||
README.md | ||
stack.yaml | ||
stamina.cabal |
Stamina
A retry Haskell library for humans:
- Exponential backoff with jitter between retries.
- Limit the attempts of retries and total time.
Stamina.HTTP
for retrying retriableNetwork.HTTP.Client
exceptions.- Introspectable retry state for logging using
RetryStatus
, including the exception that occured. - Support resetting the retry state when the action is long-running and an attempt works.
API
RetryAction
RetryStatus
defaults
retry
retryOnExceptions
Example
import qualified Stamina
import Control.Monad.Catch (throwM)
go :: IO ()
go = do
defaults <- Stamina.defaults
Stamina.retry defaults $ \retryStatus -> do
throwM $ userError "nope"
Example to catch specific exceptions
isDoesNotExistError :: IOError -> Stamina.RetryAction
isDoesNotExistError _ = Stamina.Retry
go2 :: IO ()
go2 = do
defaults <- Stamina.defaults
Stamina.retryOnExceptions defaults (return . isDoesNotExistError) $ \retryStatus -> do
throwM $ userError "nope"
Development
-
Install devenv.sh.
-
devenv shell
-
stack build
Credits
- Heavily inspired by stamina for Python.
- retry as case study for what needs to be supported.
Test setup
main = undefined