module Worker = Make_worker(T)
The Worker module has specialized functions to spawn workers, kill workers, and run
functions on workers.
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
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.
run t ~f ~arg will run f on t with the argument arg.
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.