Jobs go in. Results come out.
Usage
jobqueue(
  globals = NULL,
  packages = NULL,
  namespace = NULL,
  init = NULL,
  max_cpus = availableCores(),
  workers = ceiling(max_cpus * 1.2),
  timeout = NULL,
  hooks = NULL,
  reformat = NULL,
  signal = FALSE,
  cpus = 1L,
  stop_id = NULL,
  copy_id = NULL
)Arguments
- globals
 A named list of variables that all
<job>$exprs 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'senvironment.- init
 A call or R expression wrapped in curly braces to evaluate on each
workerjust once, immediately after start-up. Will have access to variables defined byglobalsand assets frompackagesandnamespace. Returned value is ignored.- max_cpus
 Total number of CPU cores that can be reserved by all running
jobs(sum(<job>$cpus)). Does not enforce limits on actual CPU utilization.- workers
 How many background
workerprocesses to start. Set to more thanmax_cpusto enable standbyworkersto quickly swap out withworkersthat need to restart.- timeout
 A 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'. Can also limit the 'starting' state forworkers. Afunction (job)can be used in place of a number. Example:timeout = c(total = 2.5, running = 1). Seevignette('stops').- hooks
 A 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').- reformat
 Set
reformat = function (job)to define what<job>$resultshould return. The default,reformat = NULLpasses<job>$outputto<job>$resultunchanged. Seevignette('results').- signal
 Should 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').- cpus
 The default number of CPU cores per
job. Or afunction (job)that returns the number of CPU cores to reserve for a givenjob. Used to limit the number ofjobsrunning simultaneously to respect<jobqueue>$max_cpus. Does not prevent ajobfrom using more CPUs than reserved.- stop_id
 If an existing
jobin thejobqueuehas the samestop_id, thatjobwill be stopped and return an 'interrupt' condition object as its result.stop_idcan also be afunction (job)that returns thestop_idto assign to a givenjob. Astop_idofNULLdisables this feature. Seevignette('stops').- copy_id
 If an existing
jobin thejobqueuehas the samecopy_id, the newly submittedjobwill become a "proxy" for that earlierjob, returning whatever result the earlierjobreturns.copy_idcan also be afunction (job)that returns thecopy_idto assign to a givenjob. Acopy_idofNULLdisables this feature. Seevignette('stops').
Value
A jobqueue object.
Examples
jq <- jobqueue(globals = list(N = 42), workers = 2)
print(jq)
#> ── Q1 <jobqueue/R6> ────────────────────── idle ──
#> 
#>     • 0 jobs - 0 are running
#>     • 2 workers - 0 are busy
#>     • 0 of 4 CPUs are currently in use
#> 
#> ────────────── 0 jobs run in 1 secs ──────────────
job <- jq$run({ paste("N is", N) })
job$result
#> [1] "N is 42"
jq$stop()
