Retrying for humans using Haskell.
Go to file
2023-07-07 12:42:52 +01:00
.github/workflows add ci 2023-07-04 16:19:58 +01:00
src use DiffTime, rename options 2023-07-07 12:41:50 +01: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 README, devenv, compile it 2023-07-04 16:57:03 +01:00
devenv.nix README, devenv, compile it 2023-07-04 16:57:03 +01:00
devenv.yaml README, devenv, compile it 2023-07-04 16:57:03 +01:00
LICENSE Initial commit. 2023-07-04 15:38:37 +01:00
README.md README: sync API 2023-07-07 12:42:52 +01:00
stack.yaml README, devenv, compile it 2023-07-04 16:57:03 +01:00
stamina.cabal use DiffTime, rename options 2023-07-07 12:41:50 +01: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.

API

import Control.Exception (Exception, Handler)
import Control.Monad.IO.Class (MonadIO)
import Data.Time.Clock (DiffTime)

defaults :: RetrySettings

data RetryStatus = RetryStatus
  { attempts :: Int,
    delay :: DiffTime,
    totalDelay :: DiffTime
  }

-- Retry on all sync exceptions
retry :: MonadIO m 
      => RetrySettings 
      -> (RetryStatus -> m a)
      -> m a

-- Retry on specific exceptions
retryOnExceptions :: (Exception e, MonadIO m) 
                  => RetrySettings 
                  -> [Handler RetryAction] 
                  -> (RetryStatus -> m a)
                  -> m a

data RetryAction = Skip | Retry | RetryAfter Int

Example


import qualified Stamina

main :: IO ()
main = do
    Stamina.retry Stamina.defaults $ \retryStatus -> do
        ... monadic logic that raises exceptions

Development

  1. Install devenv.sh.

  2. devenv shell

  3. stack build

Credits