Where job expressions are evaluated.
Active bindings
hooks
A named list of currently registered callback hooks.
job
The currently running
job
.ps
The
ps::ps_handle()
object for the background process.state
The
worker's
state:'starting'
,'idle'
,'busy'
, or'stopped'
.uid
A short string, e.g.
'W11'
, that uniquely identifies thisworker
.tmp
The
worker's
temporary directory.cnd
The error that caused the
worker
to stop.
Methods
Method new()
Creates a background R process for running jobs
.
Usage
worker_class$new(
globals = NULL,
packages = NULL,
namespace = NULL,
init = NULL,
hooks = NULL,
wait = TRUE,
timeout = Inf
)
Arguments
globals
A named list of variables that all
<job>$expr
s will have access to. Alternatively, an object that can be coerced to a named list withas.list()
, e.g. named vector, data.frame, or environment.packages
Character vector of package names to load on
workers
.namespace
The name of a package to attach to the
worker's
environment.init
A call or R expression wrapped in curly braces to evaluate on each
worker
just once, immediately after start-up. Will have access to variables defined byglobals
and assets frompackages
andnamespace
. Returned value is ignored.hooks
A named list of functions to run when the
worker
state changes, of the formhooks = list(idle = function (worker) {...})
. Names ofworker
hooks are typicallystarting
,idle
,busy
,stopped
, or'*'
(duplicates okay). Seevignette('hooks')
.wait
If
TRUE
, blocks until theworker
is 'idle'. IfFALSE
, theworker
object is returned in the 'starting' state.timeout
How long to wait for the
worker
to finish starting (in seconds). IfNA
, defaults to theworker_class$new()
argument.
Method print()
Print method for a worker
.
Method start()
Restarts a stopped worker
.
Method stop()
Stops a worker
by terminating the background process
and calling <job>$stop(reason)
on any jobs
currently
assigned to this worker
.
Method restart()
Restarts a worker
by calling <worker>$stop(reason)
and <worker>$start()
in succession.
Arguments
wait
If
TRUE
, blocks until theworker
is 'idle'. IfFALSE
, theworker
object is returned in the 'starting' state.timeout
How long to wait for the
worker
to finish starting (in seconds). IfNA
, defaults to theworker_class$new()
argument.reason
Passed to
<job>$stop()
for anyjobs
currently managed by thisworker
.cls
Passed to
<job>$stop()
for anyjobs
currently managed by thisworker
.
Method on()
Attach a callback function to execute when the worker
enters state
.
Method wait()
Blocks until the worker
enters the given state.