Preserve outbound backlog across outages, fix backoff quiet period
This commit is contained in:
@@ -42,7 +42,7 @@ defaultBackoff = Backoff 0.1 30 30
|
||||
|
||||
-- | Delay before the @attempt@-th restart: doubles from base, clamped at cap.
|
||||
backoffDelay :: Backoff -> Int -> NominalDiffTime
|
||||
backoffDelay (Backoff base cap _) attempt = go (attempt - 1) base
|
||||
backoffDelay (Backoff base cap _) attempt = go (max 0 (attempt - 1)) base
|
||||
where
|
||||
go 0 d = d
|
||||
go n d = go (n - 1) (min cap (d * 2))
|
||||
@@ -68,13 +68,13 @@ supervised name backoff action = go 1
|
||||
[ Handler $ \(f :: Fatal) -> pure (Just (Left f))
|
||||
, Handler $ \(e :: SomeException) -> pure (Just (Right e))
|
||||
]
|
||||
end <- getCurrentTime
|
||||
case outcome of
|
||||
Nothing -> error "unreachable: supervised action returned"
|
||||
Just (Left f) -> throw f
|
||||
Just (Right e) -> do
|
||||
putStrLn $ "[" <> T.unpack name <> "] attempt " <> show attempt <> " crashed: " <> displayException e
|
||||
let delay = backoffDelay backoff attempt
|
||||
putStrLn $ "[" <> T.unpack name <> "] restarting in " <> show delay <> "s"
|
||||
putStrLn $ "[" <> T.unpack name <> "] restarting in " <> show delay
|
||||
threadDelay (round (realToFrac delay * 1000000 :: Double))
|
||||
end <- getCurrentTime
|
||||
go (nextAttempt backoff (diffUTCTime end start) attempt)
|
||||
|
||||
Reference in New Issue
Block a user