| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Hyperion.Remote
Synopsis
- newtype ServiceId = ServiceId String
- serviceIdToText :: ServiceId -> Text
- serviceIdToString :: ServiceId -> String
- data WorkerMessage
- data RemoteError = RemoteError ServiceId RemoteErrorType
- data RemoteErrorType
- = RemoteAsyncFailed DiedReason
- | RemoteAsyncLinkFailed DiedReason
- | RemoteAsyncCancelled
- | RemoteAsyncPending
- | RemoteException String
- data WorkerConnectionTimeout = WorkerConnectionTimeout ServiceId
- data WorkerLauncher j = WorkerLauncher {
- withLaunchedWorker :: forall b. NodeId -> ServiceId -> (j -> Process b) -> Process b
- connectionTimeout :: Maybe NominalDiffTime
- onRemoteError :: forall b. RemoteError -> Process b -> Process b
- runProcessLocal :: Process a -> IO a
- runProcessLocalWithRT :: RemoteTable -> Process a -> IO a
- runProcessLocalWithRT_ :: RemoteTable -> Process () -> IO ()
- getExternalHostName :: IO String
- addressToNodeId :: Text -> NodeId
- nodeIdToAddress :: NodeId -> Text
- masterNodeIdLabel :: String
- masterNodeIdStatic :: Static (Maybe NodeId)
- getMasterNodeId :: Process (Maybe NodeId)
- registerMasterNodeId :: Maybe NodeId -> RemoteTable -> RemoteTable
- initWorkerRemoteTable :: Maybe NodeId -> RemoteTable
- worker :: NodeId -> ServiceId -> Process ()
- withServiceId :: (ServiceId -> Process a) -> Process a
- withService :: Show j => WorkerLauncher j -> (NodeId -> ServiceId -> Process a) -> Process a
- data SerializableClosureProcess a = SerializableClosureProcess {
- runClosureProcess :: Process (Closure (Process (Either String a)))
- staticSDict :: Closure (SerializableDict (Either String a))
- closureVar :: MVar (Closure (Process (Either String a)))
- getClosure :: SerializableClosureProcess a -> Process (Closure (Process (Either String a)))
- type RemoteProcessRunner = forall a. (Binary a, Typeable a) => SerializableClosureProcess a -> Process a
- withRemoteRunProcess :: Show j => WorkerLauncher j -> (RemoteProcessRunner -> Process a) -> Process a
- tryLogException :: Process b -> Process (Either String b)
- mkSerializableClosureProcess :: Typeable b => Closure (Dict (Serializable b)) -> Process (Closure (Process b)) -> Process (SerializableClosureProcess b)
Types
Type for service id. ServiceId is typically a random string that
is assigned to a worker. (Maybe to other things too?)
serviceIdToText :: ServiceId -> Text Source #
serviceIdToString :: ServiceId -> String Source #
data WorkerMessage Source #
Type for basic master to worker messaging
Instances
| Read WorkerMessage Source # | |
Defined in Hyperion.Remote Methods readsPrec :: Int -> ReadS WorkerMessage # readList :: ReadS [WorkerMessage] # | |
| Show WorkerMessage Source # | |
Defined in Hyperion.Remote Methods showsPrec :: Int -> WorkerMessage -> ShowS # show :: WorkerMessage -> String # showList :: [WorkerMessage] -> ShowS # | |
| Generic WorkerMessage Source # | |
Defined in Hyperion.Remote Associated Types type Rep WorkerMessage :: Type -> Type # | |
| Binary WorkerMessage Source # | |
Defined in Hyperion.Remote | |
| type Rep WorkerMessage Source # | |
data RemoteError Source #
Constructors
| RemoteError ServiceId RemoteErrorType |
Instances
| Show RemoteError Source # | |
Defined in Hyperion.Remote Methods showsPrec :: Int -> RemoteError -> ShowS # show :: RemoteError -> String # showList :: [RemoteError] -> ShowS # | |
| Exception RemoteError Source # | |
Defined in Hyperion.Remote Methods toException :: RemoteError -> SomeException # fromException :: SomeException -> Maybe RemoteError # displayException :: RemoteError -> String # | |
data RemoteErrorType Source #
Detailed type for RemoteError. The constructors correspond to various
possible AsyncResults.
Constructors
| RemoteAsyncFailed DiedReason | |
| RemoteAsyncLinkFailed DiedReason | |
| RemoteAsyncCancelled | |
| RemoteAsyncPending | |
| RemoteException String |
Instances
| Show RemoteErrorType Source # | |
Defined in Hyperion.Remote Methods showsPrec :: Int -> RemoteErrorType -> ShowS # show :: RemoteErrorType -> String # showList :: [RemoteErrorType] -> ShowS # | |
data WorkerConnectionTimeout Source #
Constructors
| WorkerConnectionTimeout ServiceId |
Instances
| Show WorkerConnectionTimeout Source # | |
Defined in Hyperion.Remote Methods showsPrec :: Int -> WorkerConnectionTimeout -> ShowS # show :: WorkerConnectionTimeout -> String # showList :: [WorkerConnectionTimeout] -> ShowS # | |
| Exception WorkerConnectionTimeout Source # | |
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"
nodeIdToAddress :: NodeId -> Text Source #
Inverse to addressToNodeId
masterNodeIdStatic :: Static (Maybe NodeId) Source #
getMasterNodeId :: Process (Maybe NodeId) Source #
registerMasterNodeId :: Maybe NodeId -> RemoteTable -> RemoteTable Source #
initWorkerRemoteTable :: Maybe NodeId -> RemoteTable Source #
Arguments
| :: NodeId |
|
| -> ServiceId |
|
| -> 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 #
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.