worker_class | R Documentation |
Where job expressions are evaluated.
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 this
worker
.
tmp
The worker's
temporary directory.
cnd
The error that caused the worker
to stop.
new()
Creates a background R process for running jobs
.
worker_class$new( globals = NULL, packages = NULL, namespace = NULL, init = NULL, hooks = NULL, wait = TRUE, timeout = Inf )
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 with as.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 by globals
and assets from
packages
and namespace
. Returned value is ignored.
hooks
A named list of functions to run when the
worker
state changes, of the form
hooks = list(idle = function (worker) {...})
. Names of
worker
hooks are typically starting
, idle
,
busy
, stopped
, or '*'
(duplicates okay).
See vignette('hooks')
.
wait
If TRUE
, blocks until the worker
is 'idle'.
If FALSE
, the worker
object is returned in the
'starting' state.
timeout
How long to wait for the worker
to finish
starting (in seconds). If NA
, defaults to the worker_class$new()
argument.
A worker
object.
print()
Print method for a worker
.
worker_class$print(...)
...
Arguments are not used currently.
The worker
, invisibly.
start()
Restarts a stopped worker
.
worker_class$start(wait = TRUE, timeout = NA)
wait
If TRUE
, blocks until the worker
is 'idle'.
If FALSE
, the worker
object is returned in the
'starting' state.
timeout
How long to wait for the worker
to finish
starting (in seconds). If NA
, defaults to the worker_class$new()
argument.
The worker
, invisibly.
stop()
Stops a worker
by terminating the background process
and calling <job>$stop(reason)
on any jobs
currently
assigned to this worker
.
worker_class$stop(reason = "worker stopped by user", cls = NULL)
reason
Passed to <job>$stop()
for any jobs
currently managed by this worker
.
cls
Passed to <job>$stop()
for any jobs
currently
managed by this worker
.
The worker
, invisibly.
restart()
Restarts a worker
by calling <worker>$stop(reason)
and <worker>$start()
in succession.
worker_class$restart( wait = TRUE, timeout = NA, reason = "restarting worker", cls = NULL )
wait
If TRUE
, blocks until the worker
is 'idle'.
If FALSE
, the worker
object is returned in the
'starting' state.
timeout
How long to wait for the worker
to finish
starting (in seconds). If NA
, defaults to the worker_class$new()
argument.
reason
Passed to <job>$stop()
for any jobs
currently managed by this worker
.
cls
Passed to <job>$stop()
for any jobs
currently
managed by this worker
.
The worker
, invisibly.
on()
Attach a callback function to execute when the worker
enters state
.
worker_class$on(state, func)
state
The name of a worker
state. Typically one of:
'*'
- Every time the state changes.
'.next'
- Only one time, the next time the state changes.
'starting'
- Waiting for the background process to load.
'idle'
- Waiting for jobs
to be $run()
.
'busy'
- While a job
is running.
'stopped'
- After <worker>$stop()
is called.
func
A function that accepts a worker
object as
input. You can call <worker>$stop()
and other <worker>$
methods.
A function that when called removes this callback from the
worker
.
wait()
Blocks until the worker
enters the given state.
worker_class$wait(state = "idle", timeout = Inf, signal = TRUE)
state
The name of a worker
state. Typically one of:
'*'
- Every time the state changes.
'.next'
- Only one time, the next time the state changes.
'starting'
- Waiting for the background process to load.
'idle'
- Waiting for jobs
to be $run()
.
'busy'
- While a job
is running.
'stopped'
- After <worker>$stop()
is called.
timeout
Stop the worker
if it takes longer than
this number of seconds.
signal
Raise an error if encountered (will also be recorded in
<worker>$cnd
).
This worker
, invisibly.
run()
Assigns a job
to this worker
for
evaluation on the background process.
worker_class$run(job)
job
A job
object, as created by job_class$new()
.
This worker
, invisibly.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.