Do some debug logging during delivery in outbox POST handler
This commit is contained in:
parent
770983e829
commit
f88dcef0d7
2 changed files with 57 additions and 6 deletions
|
@ -59,7 +59,7 @@ import Network.HTTP.Types.Header
|
||||||
import Network.HTTP.Types.URI
|
import Network.HTTP.Types.URI
|
||||||
import Network.TLS hiding (SHA256)
|
import Network.TLS hiding (SHA256)
|
||||||
import UnliftIO.Exception (try)
|
import UnliftIO.Exception (try)
|
||||||
import Yesod.Core hiding (logError, logWarn, logInfo)
|
import Yesod.Core hiding (logError, logWarn, logInfo, logDebug)
|
||||||
import Yesod.Persist.Core
|
import Yesod.Persist.Core
|
||||||
|
|
||||||
import qualified Data.ByteString.Lazy as BL
|
import qualified Data.ByteString.Lazy as BL
|
||||||
|
@ -1548,16 +1548,33 @@ handleOutboxNote host (Note mluNote luAttrib aud muParent muContext mpublished c
|
||||||
)
|
)
|
||||||
-> Worker ()
|
-> Worker ()
|
||||||
deliverRemoteHttp hContext obid doc (fetched, unfetched, unknown) = do
|
deliverRemoteHttp hContext obid doc (fetched, unfetched, unknown) = do
|
||||||
|
logDebug' "Starting"
|
||||||
let deliver fwd h inbox = do
|
let deliver fwd h inbox = do
|
||||||
let fwd' = if h == hContext then Just fwd else Nothing
|
let fwd' = if h == hContext then Just fwd else Nothing
|
||||||
(isJust fwd',) <$> deliverHttp doc fwd' h inbox
|
(isJust fwd',) <$> deliverHttp doc fwd' h inbox
|
||||||
now <- liftIO getCurrentTime
|
now <- liftIO getCurrentTime
|
||||||
|
logDebug' $
|
||||||
|
"Launching fetched " <> T.pack (show $ map (snd . fst) fetched)
|
||||||
traverse_ (fork . deliverFetched deliver now) fetched
|
traverse_ (fork . deliverFetched deliver now) fetched
|
||||||
|
logDebug' $
|
||||||
|
"Launching unfetched " <> T.pack (show $ map (snd . fst) unfetched)
|
||||||
traverse_ (fork . deliverUnfetched deliver now) unfetched
|
traverse_ (fork . deliverUnfetched deliver now) unfetched
|
||||||
|
logDebug' $
|
||||||
|
"Launching unknown " <> T.pack (show $ map (snd . fst) unknown)
|
||||||
traverse_ (fork . deliverUnfetched deliver now) unknown
|
traverse_ (fork . deliverUnfetched deliver now) unknown
|
||||||
|
logDebug' "Done (async delivery may still be running)"
|
||||||
where
|
where
|
||||||
|
logDebug' t = logDebug $ prefix <> t
|
||||||
|
where
|
||||||
|
prefix =
|
||||||
|
T.concat
|
||||||
|
[ "Outbox POST handler: deliverRemoteHttp obid#"
|
||||||
|
, T.pack $ show obid
|
||||||
|
, ": "
|
||||||
|
]
|
||||||
fork = forkWorker "Outbox POST handler: HTTP delivery"
|
fork = forkWorker "Outbox POST handler: HTTP delivery"
|
||||||
deliverFetched deliver now ((_, h), recips@(r :| rs)) = do
|
deliverFetched deliver now ((_, h), recips@(r :| rs)) = do
|
||||||
|
logDebug'' "Starting"
|
||||||
let (raid, luActor, luInbox, dlid) = r
|
let (raid, luActor, luInbox, dlid) = r
|
||||||
(_, e) <- deliver luActor h luInbox
|
(_, e) <- deliver luActor h luInbox
|
||||||
e' <- case e of
|
e' <- case e of
|
||||||
|
@ -1598,7 +1615,10 @@ handleOutboxNote host (Note mluNote luAttrib aud muParent muContext mpublished c
|
||||||
updateWhere [RemoteActorId ==. raid, RemoteActorErrorSince ==. Nothing] [RemoteActorErrorSince =. Just now]
|
updateWhere [RemoteActorId ==. raid, RemoteActorErrorSince ==. Nothing] [RemoteActorErrorSince =. Just now]
|
||||||
update dlid [DeliveryRunning =. False]
|
update dlid [DeliveryRunning =. False]
|
||||||
Right _resp -> delete dlid
|
Right _resp -> delete dlid
|
||||||
|
where
|
||||||
|
logDebug'' t = logDebug' $ T.concat ["deliverFetched ", h, t]
|
||||||
deliverUnfetched deliver now ((iid, h), recips@(r :| rs)) = do
|
deliverUnfetched deliver now ((iid, h), recips@(r :| rs)) = do
|
||||||
|
logDebug'' "Starting"
|
||||||
let (uraid, luActor, udlid) = r
|
let (uraid, luActor, udlid) = r
|
||||||
e <- fetchRemoteActor iid h luActor
|
e <- fetchRemoteActor iid h luActor
|
||||||
let e' = case e of
|
let e' = case e of
|
||||||
|
@ -1643,6 +1663,8 @@ handleOutboxNote host (Note mluNote luAttrib aud muParent muContext mpublished c
|
||||||
delete udlid
|
delete udlid
|
||||||
insert_ $ Delivery raid obid fwd False
|
insert_ $ Delivery raid obid fwd False
|
||||||
Right _ -> delete udlid
|
Right _ -> delete udlid
|
||||||
|
where
|
||||||
|
logDebug'' t = logDebug' $ T.concat ["deliverUnfetched ", h, t]
|
||||||
|
|
||||||
retryOutboxDelivery :: Worker ()
|
retryOutboxDelivery :: Worker ()
|
||||||
retryOutboxDelivery = do
|
retryOutboxDelivery = do
|
||||||
|
|
|
@ -22,16 +22,19 @@ where
|
||||||
|
|
||||||
import Prelude
|
import Prelude
|
||||||
|
|
||||||
|
import Control.Exception
|
||||||
|
import Control.Monad.Logger.CallStack
|
||||||
import Data.ByteString (ByteString)
|
import Data.ByteString (ByteString)
|
||||||
import Data.List.NonEmpty (NonEmpty)
|
import Data.List.NonEmpty (NonEmpty)
|
||||||
import Data.Text (Text)
|
import Data.Text (Text)
|
||||||
import Yesod.Core
|
import Network.HTTP.Client
|
||||||
|
import Network.HTTP.Types.Header
|
||||||
|
import Yesod.Core hiding (logError, logDebug)
|
||||||
|
|
||||||
import qualified Data.ByteString.Lazy as BL
|
import qualified Data.ByteString.Lazy as BL
|
||||||
|
import qualified Data.Text as T
|
||||||
|
|
||||||
import Network.HTTP.Client
|
|
||||||
import Network.HTTP.Signature
|
import Network.HTTP.Signature
|
||||||
import Network.HTTP.Types.Header
|
|
||||||
|
|
||||||
import Network.FedURI
|
import Network.FedURI
|
||||||
import Web.ActivityPub
|
import Web.ActivityPub
|
||||||
|
@ -62,7 +65,20 @@ deliverActivity inbox mfwd doc@(Doc hAct activity) = do
|
||||||
headers <- asksSite sitePostSignedHeaders
|
headers <- asksSite sitePostSignedHeaders
|
||||||
(keyid, sign) <- siteGetHttpSign
|
(keyid, sign) <- siteGetHttpSign
|
||||||
let sender = renderFedURI $ l2f hAct (activityActor activity)
|
let sender = renderFedURI $ l2f hAct (activityActor activity)
|
||||||
httpPostAP manager inbox headers keyid sign sender (Left <$> mfwd) doc
|
result <-
|
||||||
|
httpPostAP manager inbox headers keyid sign sender (Left <$> mfwd) doc
|
||||||
|
case result of
|
||||||
|
Left err ->
|
||||||
|
logError $ T.concat
|
||||||
|
[ "deliverActivity to inbox <", renderFedURI inbox
|
||||||
|
, "> error: ", T.pack $ displayException err
|
||||||
|
]
|
||||||
|
Right resp ->
|
||||||
|
logDebug $ T.concat
|
||||||
|
[ "deliverActivity to inbox <", renderFedURI inbox
|
||||||
|
, "> success: ", T.pack $ show $ responseStatus resp
|
||||||
|
]
|
||||||
|
return result
|
||||||
|
|
||||||
forwardActivity
|
forwardActivity
|
||||||
:: ( MonadSite m
|
:: ( MonadSite m
|
||||||
|
@ -81,4 +97,17 @@ forwardActivity inbox sig rSender body = do
|
||||||
(keyid, sign) <- siteGetHttpSign
|
(keyid, sign) <- siteGetHttpSign
|
||||||
renderUrl <- askUrlRender
|
renderUrl <- askUrlRender
|
||||||
let sender = renderUrl rSender
|
let sender = renderUrl rSender
|
||||||
httpPostAPBytes manager inbox headers keyid sign sender (Just $ Right sig) body
|
result <-
|
||||||
|
httpPostAPBytes manager inbox headers keyid sign sender (Just $ Right sig) body
|
||||||
|
case result of
|
||||||
|
Left err ->
|
||||||
|
logError $ T.concat
|
||||||
|
[ "forwardActivity to inbox <", renderFedURI inbox
|
||||||
|
, "> error: ", T.pack $ displayException err
|
||||||
|
]
|
||||||
|
Right resp ->
|
||||||
|
logDebug $ T.concat
|
||||||
|
[ "forwardActivity to inbox <", renderFedURI inbox
|
||||||
|
, "> success: ", T.pack $ show $ responseStatus resp
|
||||||
|
]
|
||||||
|
return result
|
||||||
|
|
Loading…
Reference in a new issue