Up

Module Make_worker (S : Worker_spec) : Worker with type 'a functions := 'a S.functions with type init_arg := S.init_arg

module Worker = Make_worker(T)

The Worker module has specialized functions to spawn workers, kill workers, and run functions on workers.

Parameters

Signature

type t

A Worker.t type is defined with bin_io so it is possible to create functions that take a worker as an argument. See sample code for examples

val __bin_read_t__ : (int -> t) Core.Std.Bin_prot.Read.reader
type 'a functions
type init_arg
val functions : t functions

Accessor for the functions implemented by this worker type

val spawn : ?where:[
| `Local
| `Remote of _ Remote_executable.t
] -> ?disown:bool -> ?env:(string * string) list -> ?rpc_max_message_size:int -> ?rpc_handshake_timeout:Core.Std.Time.Span.t -> ?rpc_heartbeat_config:Async.Std.Rpc.Connection.Heartbeat_config.t -> ?connection_timeout:Core.Std.Time.Span.t -> ?cd:string -> ?umask:int -> redirect_stdout:Fd_redirection.t -> redirect_stderr:Fd_redirection.t -> init_arg -> on_failure:(Core.Std.Error.t -> unit) -> t Core.Std.Or_error.t Async.Std.Deferred.t

spawn_worker arg ?where ?on_failure ?disown () will create a worker on where that can subsequently run some functions.

where defaults to `Local but can be specified to be some remote host.

Specifying ?log_dir as a folder on the worker machine leads to the worker redirecting its stdout and stderr to files in this folder, named with the worker id. When ?name is also specified, the log file will use this name instead.

on_failure will be called when the spawned worker either loses connection or raises a background exception.

disown defaults to false. If it is set to true then this worker will not shutdown upon losing connection with the master process. It will continue to report back any exceptions as long as it remains connected to the master. The spawned workers will be running with some name name.exe.XXXXXXXX where name.exe was the name of the original running executable.

val spawn_exn : ?where:[
| `Local
| `Remote of _ Remote_executable.t
] -> ?disown:bool -> ?env:(string * string) list -> ?rpc_max_message_size:int -> ?rpc_handshake_timeout:Core.Std.Time.Span.t -> ?rpc_heartbeat_config:Async.Std.Rpc.Connection.Heartbeat_config.t -> ?connection_timeout:Core.Std.Time.Span.t -> ?cd:string -> ?umask:int -> redirect_stdout:Fd_redirection.t -> redirect_stderr:Fd_redirection.t -> init_arg -> on_failure:(Core.Std.Error.t -> unit) -> t Async.Std.Deferred.t
val run : t -> f:(t, 'query, 'response) Function.t -> arg:'query -> 'response Core.Std.Or_error.t Async.Std.Deferred.t

run t ~f ~arg will run f on t with the argument arg.

val run_exn : t -> f:(t, 'query, 'response) Function.t -> arg:'query -> 'response Async.Std.Deferred.t

async_log t will return a Pipe.Reader.t collecting messages corresponding to Log.Global calls in t. You need not be the master of t to get its log.

Note: there is no queueing of log messages on the worker side, so all log messages that were written before the call to async_log will not be written to the pipe. A consequence of this is that you will never get any log messages written in a worker's init function.

kill t will close the established connection with the spawned worker and kill the worker process. Subsequent calls to run or kill on this worker will result in an error. kill only works from the master that initially spawned the worker, and will fail with an error if you run it from any other process.

val kill_exn : t -> unit Async.Std.Deferred.t
val host_and_port : t -> Core.Std.Host_and_port.t

Get the underlying host/port information of the given worker