The job object encapsulates an expression and its evaluation
parameters. It also provides a way to check for and retrieve the result.
Active bindings
exprR expression that will be run by this
job.varsGet or set - List of variables that will be placed into the expression's environment before evaluation.
reformatGet or set -
function (job)for defining<job>$result.signalGet or set - Conditions to signal.
cpusGet or set - Number of CPUs to reserve for evaluating
expr.timeoutGet or set - Time limits to apply to this
job.proxyGet or set -
jobto proxy in place of runningexpr.stateGet or set - The
job'sstate:'created','submitted','queued','dispatched','starting','running', or'done'. Assigning to<job>$statewill trigger callback hooks.outputGet or set -
job'sraw output. Assigning to<job>$outputwill change thejob'sstate to'done'.jobqueueThe
jobqueuethat thisjobbelongs to.workerThe
workerthat thisjobbelongs to.resultResult of
expr. Will block untiljobis finished.hooksCurrently registered callback hooks as a named list of functions. Set new hooks with
<job>$on().is_doneTRUEorFALSEdepending on if thejob'sresult is ready.uidA short string, e.g.
'J16', that uniquely identifies thisjob.
Methods
Method new()
Creates a job object defining how to run an expression on
a background worker process.
Typically you won't need to call job_class$new(). Instead, create a
jobqueue and use <jobqueue>$run() to generate
job objects.
Usage
job_class$new(
expr,
vars = NULL,
timeout = NULL,
hooks = NULL,
reformat = NULL,
signal = FALSE,
cpus = 1L,
...
)Arguments
exprA call or R expression wrapped in curly braces to evaluate on a
worker. Will have access to any variables defined byvars, as well as theworker'sglobals,packages, andinitconfiguration. Seevignette('eval').varsA named list of variables to make available to
exprduring evaluation. Alternatively, an object that can be coerced to a named list withas.list(), e.g. named vector, data.frame, or environment. Or afunction (job)that returns such an object.timeoutA named numeric vector indicating the maximum number of seconds allowed for each state the
jobpasses through, or 'total' to apply a single timeout from 'submitted' to 'done'. Or afunction (job)that returns the same. Example:timeout = c(total = 2.5, running = 1). Seevignette('stops').hooksA named list of functions to run when the
jobstate changes, of the formhooks = list(created = function (worker) {...}). Or afunction (job)that returns the same. Names ofworkerhooks are typically'created','submitted','queued','dispatched','starting','running','done', or'*'(duplicates okay). Seevignette('hooks').reformatSet
reformat = function (job)to define what<job>$resultshould return. The default,reformat = NULLpasses<job>$outputto<job>$resultunchanged. Seevignette('results').signalShould calling
<job>$resultsignal on condition objects? WhenFALSE,<job>$resultwill return the object without taking additional action. Setting toTRUEor a character vector of condition classes, e.g.c('interrupt', 'error', 'warning'), will cause the equivalent ofstop(<condition>)to be called when those conditions are produced. Alternatively, afunction (job)that returnsTRUEorFALSE. Seevignette('results').cpusHow many CPU cores to reserve for this
job. Or afunction (job)that returns the same. Used to limit the number ofjobsrunning simultaneously to respect<jobqueue>$max_cpus. Does not prevent ajobfrom using more CPUs than reserved....Arbitrary named values to add to the returned
jobobject.
Method print()
Print method for a job.
Method on()
Attach a callback function to execute when the job enters
state.
Arguments
stateThe name of a
jobstate. Typically one of:'*'- Every time the state changes.'.next'- Only one time, the next time the state changes.'created'- Afterjob_class$new()initialization.'submitted'- After<job>$jobqueueis assigned.'queued'- Afterstop_idandcopy_idare resolved.'dispatched'- After<job>$workeris assigned.'starting'- Before evaluation begins.'running'- After evaluation begins.'done'- After<job>$outputis assigned.
Custom states can also be specified.
funcA function that accepts a
jobobject as input. You can call<job>$stop()or edit<job>$values and the changes will be persisted (sincejobsare reference class objects). You can also edit/stop other queuedjobsby modifying thejobsin<job>$jobqueue$jobs. Return value is ignored.
Method wait()
Blocks until the job enters the given state.
Arguments
stateThe name of a
jobstate. Typically one of:'*'- Every time the state changes.'.next'- Only one time, the next time the state changes.'created'- Afterjob_class$new()initialization.'submitted'- After<job>$jobqueueis assigned.'queued'- Afterstop_idandcopy_idare resolved.'dispatched'- After<job>$workeris assigned.'starting'- Before evaluation begins.'running'- After evaluation begins.'done'- After<job>$outputis assigned.
Custom states can also be specified.
timeoutStop the
jobif it takes longer than this number of seconds, orNULL.
Method stop()
Stop this job. If the job is running, its
worker will be restarted.
