stamina.hs/README.md
Domen Kožar 2daca2799b garden
2023-12-30 14:57:00 +00:00

1.9 KiB

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 _ = return Stamina.Retry

go2 :: IO ()
go2 = do 
    defaults <- Stamina.defaults
    Stamina.retryOnExceptions defaults isDoesNotExistError $ \retryStatus -> do
        throwM $ userError "nope"

Development

  1. Install devenv.sh.

  2. devenv shell

  3. stack build

Credits

Test setup
main = undefined