2020-12-08 19:22:18 +00:00
|
|
|
{- types for stall detection
|
|
|
|
-
|
2021-02-03 17:19:47 +00:00
|
|
|
- Copyright 2020-2021 Joey Hess <id@joeyh.name>
|
2020-12-08 19:22:18 +00:00
|
|
|
-
|
|
|
|
- Licensed under the GNU AGPL version 3 or higher.
|
|
|
|
-}
|
|
|
|
|
|
|
|
module Types.StallDetection where
|
|
|
|
|
|
|
|
import Utility.DataUnits
|
|
|
|
import Utility.HumanTime
|
|
|
|
import Utility.Misc
|
2021-02-03 17:19:47 +00:00
|
|
|
import Git.Config
|
2020-12-08 19:22:18 +00:00
|
|
|
|
2021-02-03 17:19:47 +00:00
|
|
|
data StallDetection
|
|
|
|
= StallDetection ByteSize Duration
|
|
|
|
-- ^ Unless the given number of bytes have been sent over the given
|
|
|
|
-- amount of time, there's a stall.
|
|
|
|
| ProbeStallDetection
|
|
|
|
-- ^ Used when unsure how frequently transfer progress is updated,
|
|
|
|
-- or how fast data can be sent.
|
2021-02-03 19:35:32 +00:00
|
|
|
| StallDetectionDisabled
|
2020-12-08 19:22:18 +00:00
|
|
|
deriving (Show)
|
|
|
|
|
|
|
|
-- Parse eg, "0KiB/60s"
|
2021-02-03 17:19:47 +00:00
|
|
|
--
|
|
|
|
-- Also, it can be set to "true" (or other git config equivilants)
|
|
|
|
-- to enable ProbeStallDetection.
|
|
|
|
-- And "false" (and other git config equivilants) explicitly
|
|
|
|
-- disable stall detection.
|
|
|
|
parseStallDetection :: String -> Either String (Maybe StallDetection)
|
|
|
|
parseStallDetection s = case isTrueFalse s of
|
|
|
|
Nothing -> do
|
|
|
|
let (bs, ds) = separate (== '/') s
|
2020-12-08 19:22:18 +00:00
|
|
|
b <- maybe
|
|
|
|
(Left $ "Unable to parse stall detection amount " ++ bs)
|
|
|
|
Right
|
|
|
|
(readSize dataUnits bs)
|
|
|
|
d <- parseDuration ds
|
2021-02-03 17:19:47 +00:00
|
|
|
return (Just (StallDetection b d))
|
|
|
|
Just True -> Right (Just ProbeStallDetection)
|
2021-02-03 19:35:32 +00:00
|
|
|
Just False -> Right (Just StallDetectionDisabled)
|