2012-07-22 23:16:56 -04:00
|
|
|
{- git-annex assistant git pushing thread
|
2012-06-22 13:39:44 -04:00
|
|
|
-
|
|
|
|
- Copyright 2012 Joey Hess <joey@kitenet.net>
|
2012-06-23 01:20:40 -04:00
|
|
|
-
|
|
|
|
- Licensed under the GNU GPL version 3 or higher.
|
2012-06-22 13:39:44 -04:00
|
|
|
-}
|
|
|
|
|
2012-06-25 16:10:10 -04:00
|
|
|
module Assistant.Threads.Pusher where
|
2012-06-22 13:39:44 -04:00
|
|
|
|
2012-07-20 19:29:59 -04:00
|
|
|
import Assistant.Common
|
2012-06-22 13:39:44 -04:00
|
|
|
import Assistant.Commits
|
2012-06-25 16:38:12 -04:00
|
|
|
import Assistant.Pushes
|
2012-10-30 14:34:48 -04:00
|
|
|
import Assistant.DaemonStatus
|
2012-08-22 14:32:17 -04:00
|
|
|
import Assistant.Sync
|
2012-06-22 13:39:44 -04:00
|
|
|
import Utility.ThreadScheduler
|
2013-10-27 16:42:13 -04:00
|
|
|
import qualified Remote
|
2012-08-26 15:39:02 -04:00
|
|
|
import qualified Types.Remote as Remote
|
2012-06-22 15:46:21 -04:00
|
|
|
|
2012-06-25 16:38:12 -04:00
|
|
|
{- This thread retries pushes that failed before. -}
|
2012-10-29 11:40:22 -04:00
|
|
|
pushRetryThread :: NamedThread
|
2013-01-26 17:09:33 +11:00
|
|
|
pushRetryThread = namedThread "PushRetrier" $ runEvery (Seconds halfhour) <~> do
|
2012-06-25 16:38:12 -04:00
|
|
|
-- We already waited half an hour, now wait until there are failed
|
|
|
|
-- pushes to retry.
|
2012-10-29 17:52:43 -04:00
|
|
|
topush <- getFailedPushesBefore (fromIntegral halfhour)
|
2012-06-26 17:33:34 -04:00
|
|
|
unless (null topush) $ do
|
2012-10-29 11:40:22 -04:00
|
|
|
debug ["retrying", show (length topush), "failed pushes"]
|
2013-03-18 16:19:42 -04:00
|
|
|
void $ pushToRemotes True topush
|
2012-10-31 02:34:03 -04:00
|
|
|
where
|
|
|
|
halfhour = 1800
|
2012-06-22 13:39:44 -04:00
|
|
|
|
2012-06-25 16:38:12 -04:00
|
|
|
{- This thread pushes git commits out to remotes soon after they are made. -}
|
2012-10-29 11:40:22 -04:00
|
|
|
pushThread :: NamedThread
|
2013-01-26 17:09:33 +11:00
|
|
|
pushThread = namedThread "Pusher" $ runEvery (Seconds 2) <~> do
|
2012-09-13 00:57:52 -04:00
|
|
|
-- We already waited two seconds as a simple rate limiter.
|
|
|
|
-- Next, wait until at least one commit has been made
|
2013-04-24 17:16:04 -04:00
|
|
|
void getCommits
|
2012-09-13 00:57:52 -04:00
|
|
|
-- Now see if now's a good time to push.
|
2013-04-24 17:16:04 -04:00
|
|
|
void $ pushToRemotes True =<< pushTargets
|
2012-06-22 13:39:44 -04:00
|
|
|
|
2013-03-10 18:42:28 -04:00
|
|
|
{- We want to avoid pushing to remotes that are marked readonly.
|
|
|
|
-
|
|
|
|
- Also, avoid pushing to local remotes we can easily tell are not available,
|
|
|
|
- to avoid ugly messages when a removable drive is not attached.
|
|
|
|
-}
|
|
|
|
pushTargets :: Assistant [Remote]
|
2013-10-27 16:42:13 -04:00
|
|
|
pushTargets = liftIO . filterM (Remote.checkAvailable True)
|
|
|
|
=<< candidates <$> getDaemonStatus
|
2013-03-10 18:42:28 -04:00
|
|
|
where
|
|
|
|
candidates = filter (not . Remote.readonly) . syncGitRemotes
|