Skip to content

Commit 1a95ba7

Browse files
author
Arjun Guha
committed
finite retries
1 parent b274972 commit 1a95ba7

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

src/Database/CouchDB/HTTP.hs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module Database.CouchDB.HTTP
1111
, runCouchDB'
1212
) where
1313

14-
import System.Log.Logger (errorM,debugM)
14+
import System.Log.Logger (errorM,debugM,infoM)
1515
import Network.TCP
1616
import Network.Stream
1717
import Network.HTTP
@@ -87,13 +87,20 @@ request path query method headers body = do
8787
url <- makeURL path query
8888
let allHeaders = (makeHeaders (length body)) ++ headers
8989
conn <- getConn
90-
liftIO $ debugM "couchdb.http" $ concat [show url," ", show method]
91-
response <- liftIO $ sendHTTP conn (Request url method allHeaders body)
92-
case response of
93-
Left connErr -> do
94-
liftIO $ errorM "couchdb.http" ("request failed: " ++ show connErr)
95-
fail "server error"
96-
Right response -> return response
90+
let req = Request url method allHeaders body
91+
let retry 0 = do
92+
liftIO $ errorM "couchdb.http" $ "request failed: " ++ show req
93+
fail "server error"
94+
retry n = do
95+
response <- liftIO $ sendHTTP conn req
96+
case response of
97+
Left err -> do
98+
liftIO $ infoM "couchdb.http" $ "request failed; " ++ show n ++
99+
" more tries left: " ++ show req
100+
retry (n-1)
101+
Right val -> return val
102+
retry 2
103+
97104

98105
runCouchDB :: String -- ^hostname
99106
-> Int -- ^port

0 commit comments

Comments
 (0)