ntf-server: carry retry reason in PPRetryLater, log retries

Change PPRetryLater from nullary to PPRetryLater Text so the cause
(503 / 410-reason) propagates to the retry call site. Log a warning
at every retry attempt with provider, token id and reason.
This commit is contained in:
sh
2026-05-15 12:48:39 +00:00
parent fd298ae328
commit 7c8c142694
2 changed files with 8 additions and 7 deletions
@@ -672,8 +672,8 @@ ntfPush s@NtfPushServer {pushQ} = forever $ do
runExceptT (deliver tkn ntf) >>= \case
Right _ -> pure $ Right ()
Left e -> case e of
PPConnection _ -> retryDeliver
PPRetryLater -> retryDeliver
PPConnection ce -> retryDeliver $ "connection " <> tshow ce
PPRetryLater r -> retryDeliver r
PPCryptoError _ -> err e
PPResponseError {} -> err e
PPTokenInvalid r -> do
@@ -681,8 +681,9 @@ ntfPush s@NtfPushServer {pushQ} = forever $ do
err e
PPPermanentError -> err e
where
retryDeliver :: IO (Either PushProviderError ())
retryDeliver = do
retryDeliver :: Text -> IO (Either PushProviderError ())
retryDeliver reason = do
logWarn $ "retrying push (" <> tshow pp <> ", " <> tshow ntfTknId <> "): " <> reason
deliver <- newPushClient s pp
runExceptT (deliver tkn ntf) >>= \case
Right _ -> pure $ Right ()
@@ -326,7 +326,7 @@ data PushProviderError
| PPCryptoError C.CryptoError
| PPResponseError (Maybe Status) Text
| PPTokenInvalid NTInvalidReason
| PPRetryLater
| PPRetryLater Text
| PPPermanentError
deriving (Show, Exception)
@@ -373,8 +373,8 @@ apnsPushProviderClient c@APNSPushClient {nonceDrg, apnsCfg} tkn@NtfTknRec {token
| status == Just N.gone410 = throwE $ case reason' of
"ExpiredToken" -> PPTokenInvalid NTIRExpiredToken
"Unregistered" -> PPTokenInvalid NTIRUnregistered
_ -> PPRetryLater
| status == Just N.serviceUnavailable503 = liftIO (disconnectApnsHTTP2Client c) >> throwE PPRetryLater
_ -> PPRetryLater $ "410 " <> reason'
| status == Just N.serviceUnavailable503 = liftIO (disconnectApnsHTTP2Client c) >> throwE (PPRetryLater "503")
-- Just tooManyRequests429 -> TooManyRequests - too many requests for the same token
| otherwise = throwE $ PPResponseError status reason'
liftHTTPS2 a = ExceptT $ first PPConnection <$> a