Skip to content

moysesb/glue

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

50 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Building Better Services

Build Status

This package provides methods to deal with the common needs of services talking to other services, like timeouts and retries, treating these as cross-cutting concerns that aren't tied to a specific transport like HTTP.

Examples

Retries

Often we want to retry service calls if they've failed because it might've been a transient error that subsequently succeeds.

failingService :: IORef Int -> Int -> IO Int
failingService ref request = do
                                counter <- atomicModifyIORef' ref (\c -> (c + 1, c + 1))
                                if counter `mod` 3 == 0 then fail "Bang!" else return (request * 2)

notSoFailingService :: IO (Int -> IO Int)
notSoFailingService = do
                        ref <- liftIO $ newIORef 0
                        return $ retryingService defaultRetryOptions $ failingService ref

Caching

serviceThatNeedsCaching :: Int -> IO Int
serviceThatNeedsCaching request = do
                                    putStrLn "Doing Something Expensive!"
                                    return (request * 2)

cachedService :: IO (Int -> IO Int)
cachedService = do
                  cache <- newAtomicLRU $ Just 100
                  return $ cacheWithLRU cache serviceThatNeedsCaching

About

Transform services into better services.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Haskell 100.0%