From dcd13663d9b8610534d5c9c21128727a3ef0012c Mon Sep 17 00:00:00 2001 From: voidlizard Date: Thu, 23 Jan 2025 05:38:49 +0300 Subject: [PATCH] wip. Better wait. Uses the probe Download.wip ... instead of sqlite query (RpcDownloadList) --- hbs2-git3/app/GitRemoteHelper.hs | 2 +- hbs2-git3/lib/HBS2/Git3/Import.hs | 16 +++++++++++----- hbs2-peer/app/BlockDownloadNew.hs | 2 +- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/hbs2-git3/app/GitRemoteHelper.hs b/hbs2-git3/app/GitRemoteHelper.hs index 15ace050..8e27f1c2 100644 --- a/hbs2-git3/app/GitRemoteHelper.hs +++ b/hbs2-git3/app/GitRemoteHelper.hs @@ -194,7 +194,7 @@ main = flip runContT pure do url <- case cli of [ ListVal [_, RepoURL x ] ] -> do - notice $ "FUCKING REMOTE" <+> pretty (AsBase58 x) + notice $ "git remote ref set:" <+> green (pretty (AsBase58 x)) setGitRepoKey x pure $ Just x diff --git a/hbs2-git3/lib/HBS2/Git3/Import.hs b/hbs2-git3/lib/HBS2/Git3/Import.hs index b90fa264..661627d5 100644 --- a/hbs2-git3/lib/HBS2/Git3/Import.hs +++ b/hbs2-git3/lib/HBS2/Git3/Import.hs @@ -113,6 +113,8 @@ data ImportStage = | ImportWait (Maybe Int) ImportStage | ImportDone (Maybe HashRef) +{- HLINT ignore "Functor law" -} + importGitRefLog :: forall m . ( HBS2GitPerks m -- , HasStorage m -- , HasClientAPI PeerAPI UNIX m @@ -145,16 +147,20 @@ importGitRefLog = withStateDo $ ask >>= \case ImportWait d next -> do - down <- callRpcWaitMay @RpcDownloadList (TimeoutSec 1) peerAPI () - >>= orThrow RpcTimeout - <&> fromIntegral . L.length + pause @'Seconds 1.15 + + down <- callRpcWaitRetry @RpcGetProbes (TimeoutSec 1) 3 peerAPI () + >>= orThrow RpcTimeout + <&> maybe 0 fromIntegral . headMay . mapMaybe \case + ProbeSnapshotElement "Download.wip" n -> Just n + _ -> Nothing notice $ "wait some time..." <+> parens (pretty down) case d of - Just n | down < n || down == 0 -> again next + Just n | down /= n || down == 0 -> again next - _ -> pause @'Seconds 3 >> again (ImportWait (Just down) next) + _ -> pause @'Seconds 2.85 >> again (ImportWait (Just down) next) ImportStart -> do diff --git a/hbs2-peer/app/BlockDownloadNew.hs b/hbs2-peer/app/BlockDownloadNew.hs index 16a16a2a..0602127a 100644 --- a/hbs2-peer/app/BlockDownloadNew.hs +++ b/hbs2-peer/app/BlockDownloadNew.hs @@ -650,7 +650,7 @@ downloadDispatcher probe brains env = do dupes <- newTVarIO ( mempty :: HashMap HashRef Int ) - ContT $ withAsync $ forever $ pause @'Seconds 10 >> do + ContT $ withAsync $ forever $ pause @'Seconds 2 >> do acceptReport probe =<< S.toList_ do wip <- readTVarIO wip <&> HM.size pn <- readTVarIO pts <&> HM.size