File: StallDetection.hs

package info (click to toggle)
git-annex 8.20210223-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 68,764 kB
  • sloc: haskell: 70,359; javascript: 9,103; sh: 1,304; makefile: 212; perl: 136; ansic: 44
file content (42 lines) | stat: -rw-r--r-- 1,251 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
{- types for stall detection
 -
 - Copyright 2020-2021 Joey Hess <id@joeyh.name>
 -
 - Licensed under the GNU AGPL version 3 or higher.
 -}

module Types.StallDetection where

import Utility.DataUnits
import Utility.HumanTime
import Utility.Misc
import Git.Config

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.
	| StallDetectionDisabled
	deriving (Show)

-- Parse eg, "0KiB/60s"
--
-- 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
		b <- maybe 
			(Left $ "Unable to parse stall detection amount " ++ bs)
			Right
			(readSize dataUnits bs)
		d <- parseDuration ds
		return (Just (StallDetection b d))
	Just True -> Right (Just ProbeStallDetection)
	Just False -> Right (Just StallDetectionDisabled)