Retrying for humans using Haskell.
Go to file
2023-12-30 14:55:26 +00:00
.github/workflows implement Stamina 2023-12-30 11:38:00 +00:00
src Implement Stamina.HTTP 2023-12-30 14:55:26 +00:00
test Initial commit. 2023-07-04 15:38:37 +01:00
.envrc README, devenv, compile it 2023-07-04 16:57:03 +01:00
.gitignore README, devenv, compile it 2023-07-04 16:57:03 +01:00
CHANGELOG.md Initial commit. 2023-07-04 15:38:37 +01:00
devenv.lock Implement Stamina.HTTP 2023-12-30 14:55:26 +00:00
devenv.nix Implement Stamina.HTTP 2023-12-30 14:55:26 +00:00
LICENSE Initial commit. 2023-07-04 15:38:37 +01:00
README.lhs implement Stamina 2023-12-30 11:38:00 +00:00
README.md Implement Stamina.HTTP 2023-12-30 14:55:26 +00:00
stack.yaml Implement Stamina.HTTP 2023-12-30 14:55:26 +00:00
stamina.cabal Implement Stamina.HTTP 2023-12-30 14:55:26 +00:00

Stamina

Project Status: Concept – Minimal or no implementation has been done yet, or the repository is only intended to be a limited example, demo, or proof-of-concept. Hackage CI status

A retry Haskell library for humans:

  • Exponential backoff with jitter between retries.
  • Limit the attempts of retries and total time.
  • Stamina.HTTP for retrying retriable Network.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

  1. Install devenv.sh.

  2. devenv shell

  3. stack build

Credits

Test setup
main = undefined