Let's say that I have an http server based in Scotty
scottyServer :: IO ()
scottyServer = do
print ("Starting Server at port " ++ show port)
scotty port routes
routes :: ScottyM()
routes = do get "/service" responseService
get "/users" responseUsers
And then I have a circuit breaker which I want to keep state CircuitBreakerType
data CircuitBreakerType
= Close {users::[User], error:: Integer}
| Open {users::[User], error:: Integer}
| HalfOpen {users::[User], error:: Integer}
deriving (Show)
responseUsers :: ActionM ()
responseUsers = do users <- liftAndCatchIO $ searchAllCassandraUsersCB $ Close [] 0
json (show users)
searchAllCassandraUsersCB :: CircuitBreakerType -> IO CircuitBreakerType
searchAllCassandraUsersCB (Close users errors)= do result <- selectAllCassandraUserCB $ Close users errors
return result
Using Haskell how can I keep the state of the CircuitBreakerType between request/response of Scootty
All the examples of state machine that I did was passing the state in the IO monad one to another, but with a Http server I dont have a clue how to keep the state. Hopefully nothing related with persistance in database since the performance would suck.
Regards