summaryrefslogtreecommitdiff
path: root/Assistant/Pushes.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2017-09-20 14:37:20 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2017-09-20 15:29:13 -0400
commit3826ef1923a35ef8794f0e3beb0f94f0f40fd9be (patch)
tree0a0af9d00654786c9196f8f13c973e597cfb65fd /Assistant/Pushes.hs
parentd20933a25956a3a07247f66fe3a554761d616173 (diff)
add exporter thread to assistant
This is similar to the pusher thread, but a separate thread because git pushes can be done in parallel with exports, and updating a big export should not prevent other git pushes going out in the meantime. The exportThread only runs at most every 30 seconds, since updating an export is more expensive than pushing. This may need to be tuned. Added a separate channel for export commits; the committer records a commit in that channel. Also, reconnectRemotes records a dummy commit, to make the exporter thread wake up and make sure all exports are up-to-date. So, connecting a drive with a directory special remote export will immediately update it, and getting online will automatically update S3 and WebDAV exports. The transfer queue is not involved in exports. Instead, failed exports are retried much like failed pushes. This commit was sponsored by Ewen McNeill.
Diffstat (limited to 'Assistant/Pushes.hs')
-rw-r--r--Assistant/Pushes.hs21
1 files changed, 9 insertions, 12 deletions
diff --git a/Assistant/Pushes.hs b/Assistant/Pushes.hs
index 7b4de450f..61891ea28 100644
--- a/Assistant/Pushes.hs
+++ b/Assistant/Pushes.hs
@@ -17,24 +17,21 @@ import qualified Data.Map as M
{- Blocks until there are failed pushes.
- Returns Remotes whose pushes failed a given time duration or more ago.
- (This may be an empty list.) -}
-getFailedPushesBefore :: NominalDiffTime -> Assistant [Remote]
-getFailedPushesBefore duration = do
- v <- getAssistant failedPushMap
- liftIO $ do
- m <- atomically $ readTMVar v
- now <- getCurrentTime
- return $ M.keys $ M.filter (not . toorecent now) m
+getFailedPushesBefore :: NominalDiffTime -> FailedPushMap -> Assistant [Remote]
+getFailedPushesBefore duration v = liftIO $ do
+ m <- atomically $ readTMVar v
+ now <- getCurrentTime
+ return $ M.keys $ M.filter (not . toorecent now) m
where
toorecent now time = now `diffUTCTime` time < duration
{- Modifies the map. -}
-changeFailedPushMap :: (PushMap -> PushMap) -> Assistant ()
-changeFailedPushMap a = do
- v <- getAssistant failedPushMap
- liftIO $ atomically $ store v . a . fromMaybe M.empty =<< tryTakeTMVar v
+changeFailedPushMap :: FailedPushMap -> (PushMap -> PushMap) -> Assistant ()
+changeFailedPushMap v f = liftIO $ atomically $
+ store . f . fromMaybe M.empty =<< tryTakeTMVar v
where
{- tryTakeTMVar empties the TMVar; refill it only if
- the modified map is not itself empty -}
- store v m
+ store m
| m == M.empty = noop
| otherwise = putTMVar v $! m