Create a controller object from a client and launcher.
Source:R/crew_controller.R
crew_controller.RdThis function is for developers of crew launcher plugins.
Users should use a specific controller helper such as
crew_controller_local().
Usage
crew_controller(
client,
launcher,
reset_globals = TRUE,
reset_packages = FALSE,
reset_options = FALSE,
garbage_collection = FALSE,
crashes_max = 5L,
backup = NULL,
auto_scale = NULL
)Arguments
- client
An
R6client object created bycrew_client().- launcher
An
R6launcher object created by one of thecrew_launcher_*()functions such ascrew_launcher_local().- reset_globals
TRUEto reset global environment variables between tasks,FALSEto leave them alone.- reset_packages
TRUEto detach any packages loaded during a task (runs between each task),FALSEto leave packages alone. In either case, the namespaces are not detached.- reset_options
TRUEto reset global options to their original state between each task,FALSEotherwise. It is recommended to only setreset_options = TRUEifreset_packagesis alsoTRUEbecause packages sometimes rely on options they set at loading time. for this and other reasons,reset_optionsonly resets options that were nonempty at the beginning of the task. If your task sets an entirely new option not already inoptions(), thenreset_options = TRUEdoes not delete the option.- garbage_collection
TRUEto run garbage collection after each task task,FALSEto skip.- crashes_max
In rare cases, a worker may exit unexpectedly before it completes its current task. If this happens,
pop()returns a status of"crash"instead of"error"for the task. The controller does not automatically retry the task, but you can retry it manually by callingpush()again and using the same task name as before. (However,targetspipelines runningcrewdo automatically retry tasks whose workers crashed.)crashes_maxis a non-negative integer, and it sets the maximum number of allowable consecutive crashes for a given task. If a task's worker crashes more thancrashes_maxtimes in a row, thenpop()throws an error when it tries to return the results of the task.- backup
An optional
crewcontroller object, orNULLto omit. If supplied, thebackupcontroller runs any pushed tasks that have already reachedcrashes_maxconsecutive crashes. Usingbackup, you can create a chain of controllers with different levels of resources (such as worker memory and CPUs) so that a task that fails on one controller can retry using incrementally more powerful workers. All controllers in a backup chain should be part of the same controller group (seecrew_controller_group()) so you can call the group-levelpop()andcollect()methods to make sure you get results regardless of which controller actually ended up running the task.Limitations of
backup: *crashes_maxneeds to be positive in order forbackupto be used. Otherwise, every task would always skip the current controller and go tobackup. *backupcannot be a controller group. It must be an ordinary controller.- auto_scale
Deprecated. Use the
scaleargument ofpush(),pop(), andwait()instead.
See also
Other controller:
crew_class_controller
Examples
if (identical(Sys.getenv("CREW_EXAMPLES"), "true")) {
client <- crew_client()
launcher <- crew_launcher_local()
controller <- crew_controller(client = client, launcher = launcher)
controller$start()
controller$push(name = "task", command = sqrt(4))
controller$wait()
controller$pop()
controller$terminate()
}