Starts up an execution daemon to receive mirai()
requests. Awaits data,
evaluates an expression in an environment containing the supplied data,
and returns the value to the host caller. Daemon settings may be controlled
by daemons()
and this function should not need to be invoked directly,
unless deploying manually on remote resources.
Usage
daemon(
url,
dispatcher = TRUE,
...,
asyncdial = FALSE,
autoexit = TRUE,
cleanup = TRUE,
output = FALSE,
idletime = Inf,
walltime = Inf,
maxtasks = Inf,
id = NULL,
tls = NULL,
rs = NULL
)
Arguments
- url
the character host or dispatcher URL to dial into, including the port to connect to, e.g. 'tcp://hostname:5555' or 'tls+tcp://10.75.32.70:5555'.
- dispatcher
[default TRUE] logical value, which should be set to TRUE if using dispatcher and FALSE otherwise.
- ...
reserved but not currently used.
- asyncdial
[default FALSE] whether to perform dials asynchronously. The default FALSE will error if a connection is not immediately possible (for instance if
daemons()
has yet to be called on the host, or the specified port is not open etc.). Specifying TRUE continues retrying (indefinitely) if not immediately successful, which is more resilient but can mask potential connection issues.- autoexit
[default TRUE] logical value, whether the daemon should exit automatically when its socket connection ends. By default, the process ends immediately when the host process ends. Supply
NA
to have a daemon complete any tasks in progress before exiting (see 'Persistence' section below).- cleanup
[default TRUE] logical value, whether to perform cleanup of the global environment and restore attached packages and options to an initial state after each evaluation.
- output
[default FALSE] logical value, to output generated stdout / stderr if TRUE, or else discard if FALSE. Specify as TRUE in the
...
argument todaemons()
orlaunch_local()
to provide redirection of output to the host process (applicable only for local daemons).- idletime
[default Inf] integer milliseconds maximum time to wait for a task (idle time) before exiting.
- walltime
[default Inf] integer milliseconds soft walltime (time limit) i.e. the minimum amount of real time elapsed before exiting.
- maxtasks
[default Inf] integer maximum number of tasks to execute (task limit) before exiting.
- id
[default NULL] (optional) integer daemon ID provided to dispatcher to track connection status. Causes
status()
to report this ID under$events
when the daemon connects and disconnects.- tls
[default NULL] required for secure TLS connections over 'tls+tcp://'. Either the character path to a file containing X.509 certificate(s) in PEM format, comprising the certificate authority certificate chain starting with the TLS certificate and ending with the CA certificate, or a length 2 character vector comprising [i] the certificate authority certificate chain and [ii] the empty string
""
.- rs
[default NULL] the initial value of .Random.seed. This is set automatically using L'Ecuyer-CMRG RNG streams generated by the host process if applicable, and should not be independently supplied.
Value
Invisibly, an integer exit code: 0L for normal termination, and a positive value if a self-imposed limit was reached: 1L (idletime), 2L (walltime), 3L (maxtasks).
Details
The network topology is such that daemons dial into the host or dispatcher,
which listens at the url
address. In this way, network resources may be
added or removed dynamically and the host or dispatcher automatically
distributes tasks to all available daemons.
Persistence
The autoexit
argument governs persistence settings for the daemon. The
default TRUE ensures that it will exit as soon as its socket connection
with the host process drops.
Supplying NA
will allow a daemon to exit cleanly once its socket connection
with the host process drops, as soon as it has finished any task that is
currently in progress. This may be useful if the daemon is performing some
side effect such as writing files to disk, and the result is not required in
the host process.
Setting to FALSE allows the daemon to persist indefinitely even when there is
no longer a socket connection. This allows a host session to end and a new
session to connect at the URL where the daemon is dialled in. Daemons must be
terminated with daemons(NULL)
in this case, which sends explicit exit
signals to all connected daemons.