hyperion-0.1.0.0
Safe HaskellNone
LanguageHaskell2010

Hyperion.Remote

Synopsis

Types

newtype ServiceId Source #

Type for service id. ServiceId is typically a random string that is assigned to a worker. (Maybe to other things too?)

Constructors

ServiceId String 

Instances

Instances details
Eq ServiceId Source # 
Instance details

Defined in Hyperion.Remote

Show ServiceId Source # 
Instance details

Defined in Hyperion.Remote

Generic ServiceId Source # 
Instance details

Defined in Hyperion.Remote

Associated Types

type Rep ServiceId :: Type -> Type #

Binary ServiceId Source # 
Instance details

Defined in Hyperion.Remote

type Rep ServiceId Source # 
Instance details

Defined in Hyperion.Remote

type Rep ServiceId = D1 ('MetaData "ServiceId" "Hyperion.Remote" "hyperion-0.1.0.0-BChDBJtiU1m4GBpewNuAxw" 'True) (C1 ('MetaCons "ServiceId" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 String)))

data WorkerMessage Source #

Type for basic master to worker messaging

Constructors

Connected 
ShutDown 

Instances

Instances details
Read WorkerMessage Source # 
Instance details

Defined in Hyperion.Remote

Show WorkerMessage Source # 
Instance details

Defined in Hyperion.Remote

Generic WorkerMessage Source # 
Instance details

Defined in Hyperion.Remote

Associated Types

type Rep WorkerMessage :: Type -> Type #

Binary WorkerMessage Source # 
Instance details

Defined in Hyperion.Remote

type Rep WorkerMessage Source # 
Instance details

Defined in Hyperion.Remote

type Rep WorkerMessage = D1 ('MetaData "WorkerMessage" "Hyperion.Remote" "hyperion-0.1.0.0-BChDBJtiU1m4GBpewNuAxw" 'False) (C1 ('MetaCons "Connected" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "ShutDown" 'PrefixI 'False) (U1 :: Type -> Type))

data RemoteErrorType Source #

Detailed type for RemoteError. The constructors correspond to various possible AsyncResults.

Instances

Instances details
Show RemoteErrorType Source # 
Instance details

Defined in Hyperion.Remote

data WorkerLauncher j Source #

WorkerLauncher type parametrized by a type for job id.

Constructors

WorkerLauncher 

Fields

Functions for running a worker

runProcessLocal :: Process a -> IO a Source #

Run a Process locally using the default RemoteTable. Additionally allows a return value for the Process.

runProcessLocalWithRT :: RemoteTable -> Process a -> IO a Source #

Run a Process locally using the specified RemoteTable. Additionally allows a return value for the Process.

runProcessLocalWithRT_ :: RemoteTable -> Process () -> IO () Source #

Spawns a new local Control.Distributed.Process.Node and runs the given Process on it. Waits for the process to finish.

Binds to the first available port by specifying port 0.

getExternalHostName :: IO String Source #

Get a hostname for the current machine that does not correspond to a local network address (127.* or 10.*)

addressToNodeId :: Text -> NodeId Source #

Convert a Text representation of EndPointAddress to NodeId. The format for the end point address is "TCP host:TCP port:endpoint id"

getMasterNodeId :: Process (Maybe NodeId) Source #

worker Source #

Arguments

:: NodeId

NodeId of the master node

-> ServiceId

ServiceId of master Process (should be registered)

-> Process () 

The main worker process.

Repeatedly (at most 5 times) send our own ProcessId and the send end of a typed channel (SendPort WorkerMessage) to a master node until it replies Connected (timeout 10 seconds for each attempt). Then expect a ShutDown signal.

While waiting, other processes will be run in a different thread, invoked by master through our NodeId (which it extracts from ProcessId)

withServiceId :: (ServiceId -> Process a) -> Process a Source #

Registers (register) the current process under a random ServiceId, then passes the ServiceId to the given continuation. After the continuation returns, unregisters (unregister) the ServiceId.

withService :: Show j => WorkerLauncher j -> (NodeId -> ServiceId -> Process a) -> Process a Source #

Start a new remote worker using WorkerLauncher and call a continuation with the NodeId and ServiceId of that worker. The continuation is run in the process that is registered under the ServiceId (see withServiceId).

Throws (throwM) a WorkerConnectionTimeout if worker times out (timeout described in WorkerLauncher)

The call to the user function is bracketed by worker startup and shutdown procedures.

Functions related to running remote functions

data SerializableClosureProcess a Source #

A process that generates the Closure to be run on a remote machine.

Constructors

SerializableClosureProcess 

Fields

getClosure :: SerializableClosureProcess a -> Process (Closure (Process (Either String a))) Source #

Get closure and memoize the result

type RemoteProcessRunner = forall a. (Binary a, Typeable a) => SerializableClosureProcess a -> Process a Source #

The type of a function that takes a SerializableClosureProcess and runs the Closure on a remote machine. In case the remote machine returns a Left value (i.e. an error), throws this value wrapped in RemoteError of type RemoteException. May throw other RemoteErrors if remote execution fails in any way.

withRemoteRunProcess :: Show j => WorkerLauncher j -> (RemoteProcessRunner -> Process a) -> Process a Source #

Starts a new remote worker and runs a user function, which is supplied with RemoteProcessRunner for running closures on that worker. If a RemoteError occurs, it is handled by the onRemoteError supplied in the WorkerLauncher.

tryLogException :: Process b -> Process (Either String b) Source #

Catch any exception, log it, and return as a string. In this way, errors will be logged by the worker where they occurred, and also sent up the tree.

mkSerializableClosureProcess :: Typeable b => Closure (Dict (Serializable b)) -> Process (Closure (Process b)) -> Process (SerializableClosureProcess b) Source #

Construct a SerializableClosureProcess for evaluating the closure mb on a remote machine. The action mb that produces the Closure will only be run once -- when a worker first becomes available. The MVar v caches the resulting Closure (so it can be re-used in the event of an error and retry), which will then be sent across the network.

Note that we wrap the given closure in tryLogException. Thus, exception handling is added by catching any exception e, logging e with err (on the worker), and returning a Left result with the textual representation of e from Show instance.