hyperion-0.1.0.0
Safe HaskellNone
LanguageHaskell2010

Hyperion.Util

Synopsis

Documentation

newtype Unique Source #

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.

Constructors

MkUnique Integer 

Instances

Instances details
Eq Unique Source # 
Instance details

Defined in Hyperion.Util

Methods

(==) :: Unique -> Unique -> Bool #

(/=) :: Unique -> Unique -> Bool #

Ord Unique Source # 
Instance details

Defined in Hyperion.Util

Show Unique Source #

A Unique can be rendered to a unique string of the characters [0-9a-zA-Z]. This is used in Hyperion.Remote to generate new ServiceId's.

Instance details

Defined in Hyperion.Util

newUnique :: IO Unique Source #

Get a new Unique.

randomString :: Int -> IO String Source #

IO action that returns a random string of given length

retryRepeated Source #

Arguments

:: (Show e, MonadIO m) 
=> Int

If this is 0 (or less), then it attempt doTry m indefinitely.

-> (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.

data WaitRetry e Source #

Constructors

WaitRetry 

Fields

Instances

Instances details
Show e => Show (WaitRetry e) Source # 
Instance details

Defined in Hyperion.Util

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'.

emailError :: (Show a, MonadIO m) => Text -> a -> m () Source #

Send an email with msg Error

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.

savedExecutable Source #

Arguments

:: FilePath 
-> String

the string to append

-> IO FilePath 

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.

withDict :: forall (c :: Constraint) r. (c => r) -> Dict c -> r Source #

Turn an expression with a constraint into a function of an explicit dictionary