Safe Haskell | None |
---|---|
Language | Haskell2010 |
Hyperion.Util
Synopsis
- newtype Unique = MkUnique Integer
- uniqueSource :: IORef Integer
- newUnique :: IO Unique
- randomString :: Int -> IO String
- retryRepeated :: (Show e, MonadIO m) => Int -> (m a -> m (Either e a)) -> m a -> m a
- data WaitRetry e = WaitRetry {}
- retryExponential :: MonadIO m => (m a -> m (Either e a)) -> (WaitRetry e -> m ()) -> m a -> m a
- emailMessage :: MonadIO m => Text -> Text -> Text -> m ()
- email :: (Show a, MonadIO m) => Text -> Text -> a -> m ()
- emailError :: (Show a, MonadIO m) => Text -> a -> m ()
- shellEsc :: FilePath -> [String] -> String
- minute :: NominalDiffTime
- hour :: NominalDiffTime
- day :: NominalDiffTime
- nominalDiffTimeToMicroseconds :: NominalDiffTime -> Int
- myExecutable :: IO FilePath
- savedExecutable :: FilePath -> String -> IO FilePath
- sanitizeFileString :: String -> FilePath
- hashTruncateString :: Int -> String -> String
- hashTruncateFileName :: String -> String
- withDict :: forall (c :: Constraint) r. (c => r) -> Dict c -> r
Documentation
An opaque type representing a unique object. Only guaranteed to be unique in one instance of a running program. For example, if we allowed Unique's to be serialized and sent across the wire, or stored and retrieved from a database, they would no longer be guaranteed to be unique.
Arguments
:: (Show e, MonadIO m) | |
=> Int | If this is 0 (or less), then it attempt |
-> (m a -> m (Either e a)) | |
-> m a | |
-> m a |
retryRepeated n doTry m
tries to run doTry m
n-1 times, after
which it runs m
1 time. After each failure waits 15-90 seconds
randomly. Returns on first success. Failure is represented by a
Left
value.
retryExponential :: MonadIO m => (m a -> m (Either e a)) -> (WaitRetry e -> m ()) -> m a -> m a Source #
retryExponential doTry m
tries to run doTry m
. After the n-th
successive failure, it waits time 2^n*t0, where t0 is a randomly
chosen time between 10 and 20 seconds. Unlike retryRepeated
,
retryExponential
never eventually throws an exception, so it
should only be used when the only way to recover from the exception
without the whole program crashing is to retry until things
work. Typically this means it should only be used in the master
process.
emailMessage :: MonadIO m => Text -> Text -> Text -> m () Source #
Send an email to toAddr
with the given subject
and body
.
email :: (Show a, MonadIO m) => Text -> Text -> a -> m () Source #
Send an email to toAddr
showing the object a
. The subject
line is "msg: ...", where msg
is the first argument and "..." is
the first 40 characters of 'show a'.
shellEsc :: FilePath -> [String] -> String Source #
Takes a path and a list of String
arguments, shell-escapes the arguments,
and combines everything into a single string.
Determine the path to this executable and save a copy to the specified dir with a string appended to filename.
sanitizeFileString :: String -> FilePath Source #
Replaces all non-allowed characters by '_'
. Allowed characters are alphanumerics and .,-,_
hashTruncateString :: Int -> String -> String Source #
Truncates a string to a string of at most given length, replacing dropped characters by a hash. The hash takes up 43 symbols, so asking for a smaller length will still return 43 symbols.
hashTruncateFileName :: String -> String Source #
Synonim for hashTruncateString
230
withDict :: forall (c :: Constraint) r. (c => r) -> Dict c -> r Source #
Turn an expression with a constraint into a function of an explicit dictionary