New --time-limit option, makes long git-annex commands stop after a specified amount of time.

This commit is contained in:
Joey Hess 2012-09-25 16:48:24 -04:00
parent 995b04d36f
commit f0e0d17440
6 changed files with 63 additions and 4 deletions

View file

@ -141,9 +141,11 @@ options = Option.common ++
"skip files with fewer copies"
, Option ['B'] ["inbackend"] (ReqArg Limit.addInBackend paramName)
"skip files not using a key-value backend"
, Option ['T'] ["time-limit"] (ReqArg Limit.addTimeLimit paramTime)
"stop after the specified amount of time"
] ++ Option.matcher
where
setnumcopies v = Annex.changeState $ \s -> s {Annex.forcenumcopies = readish v }
setnumcopies v = Annex.changeState $ \s -> s { Annex.forcenumcopies = readish v }
setgitconfig :: String -> Annex ()
setgitconfig v = do
newg <- inRepo $ Git.Config.store v

View file

@ -9,6 +9,7 @@ module Limit where
import Text.Regex.PCRE.Light.Char8
import System.Path.WildMatch
import Data.Time.Clock.POSIX
import Common.Annex
import qualified Annex
@ -17,6 +18,7 @@ import qualified Remote
import qualified Backend
import Annex.Content
import Logs.Trust
import Utility.HumanTime
type Limit = Utility.Matcher.Token (FilePath -> Annex Bool)
@ -106,3 +108,17 @@ addInBackend name = addLimit $ Backend.lookupFile >=> check
where
wanted = Backend.lookupBackendName name
check = return . maybe False ((==) wanted . snd)
addTimeLimit :: String -> Annex ()
addTimeLimit s = do
let seconds = fromMaybe (error "bad time-limit") $ parseDuration s
start <- liftIO getPOSIXTime
let cutoff = start + seconds
addLimit $ const $ do
now <- liftIO getPOSIXTime
if now > cutoff
then do
warning $ "Time limit (" ++ s ++ ") reached!"
liftIO $ exitWith $ ExitFailure 101
else return True

View file

@ -77,6 +77,8 @@ paramType :: String
paramType = "TYPE"
paramDate :: String
paramDate = "DATE"
paramTime :: String
paramTime = "TIME"
paramFormat :: String
paramFormat = "FORMAT"
paramFile :: String

26
Utility/HumanTime.hs Normal file
View file

@ -0,0 +1,26 @@
{- Time for humans.
-
- Copyright 2012 Joey Hess <joey@kitenet.net>
-
- Licensed under the GNU GPL version 3 or higher.
-}
module Utility.HumanTime where
import Utility.PartialPrelude
import Data.Time.Clock.POSIX (POSIXTime)
{- Parses a human-input time duration, of the form "5h" or "1m". -}
parseDuration :: String -> Maybe POSIXTime
parseDuration s = do
num <- readish s :: Maybe Integer
units <- findUnits =<< lastMaybe s
return $ fromIntegral num * units
where
findUnits 's' = Just 1
findUnits 'm' = Just 60
findUnits 'h' = Just $ 60 * 60
findUnits 'd' = Just $ 60 * 60 * 24
findUnits 'y' = Just $ 60 * 60 * 24 * 365
findUnits _ = Nothing

2
debian/changelog vendored
View file

@ -6,6 +6,8 @@ git-annex (3.20120925) UNRELEASED; urgency=low
with git annex fsck --incremental. Now the fsck can be interrupted
as desired, and resumed with git annex fsck --more.
Thanks, Justin Azoff
* New --time-limit option, makes long git-annex commands stop after
a specified amount of time.
-- Joey Hess <joeyh@debian.org> Mon, 24 Sep 2012 19:58:07 -0400

View file

@ -259,13 +259,13 @@ subdirectories).
To check a remote to fsck, specify --from.
To avoid expensive checksum calculations (and expensive transfers when
fscking a remote), specify --fast.
To start a new incremental fsck, specify --incremental. Then
the next time you fsck, you can specify --more to skip over
files that have already been checked, and continue where it left off.
To avoid expensive checksum calculations (and expensive transfers when
fscking a remote), specify --fast.
* unused
Checks the annex for data that does not correspond to any files present
@ -514,6 +514,17 @@ subdirectories).
Overrides the `annex.numcopies` setting, forcing git-annex to ensure the
specified number of copies exist.
* --time-limit=time
Limits how long a git-annex command runs. The time can be something
like "5h", or "30m" or even "45s" or "10d".
Note that git-annex may continue running a little past the specified
time limit, in order to finish processing a file.
Also, note that if the time limit prevents git-annex from doing all it
was asked to, it will exit with a special code, 101.
* --trust=repository
* --semitrust=repository
* --untrust=repository