Nicolas Henin
Nicolas Henin

Reputation: 3334

Graceful shutdown of a process

I want to close a store connection (adding a function like close eventStoreConnection) when the process is about to shutdown :

main = do
     eventStoreConnection <- EventStore.connect EventStore.defaultSettings (EventStore.Static "127.0.0.1" 1113)
     scotty 3000 $ do
       get  "/health/liveness" $ do html "OK"
       post "/introduceIdea" $ do
          command <- jsonData
          liftIO $ persist eventStoreConnection command
          html "OK"

Upvotes: 1

Views: 130

Answers (1)

bergey
bergey

Reputation: 3071

You can use bracket. Like:

let connect = EventStore.connect EventStore.defaultSettings (EventStore.Static "127.0.0.1" 1113))
bracket connect close $ \eventStoreConnection ->
    scotty 3000 $ ...

Upvotes: 2

Related Questions