Skip to contents

R6 abstract class to build other subclasses which launch and manage workers.

See also

Other launcher: crew_launcher()

Active bindings

name

See crew_launcher().

workers

See crew_launcher().

seconds_interval

See crew_launcher().

seconds_timeout

See crew_launcher().

seconds_launch

See crew_launcher().

seconds_idle

See crew_launcher().

seconds_wall

See crew_launcher().

tasks_max

See crew_launcher().

tasks_timers

See crew_launcher().

reset_globals

See crew_launcher().

reset_packages

See crew_launcher().

reset_options

See crew_launcher().

garbage_collection

See crew_launcher().

tls

See crew_launcher().

processes

See crew_launcher(). asynchronously.

r_arguments

See crew_launcher().

options_metrics

See crew_launcher().

url

Websocket URL for worker connections.

profile

mirai compute profile of the launcher.

instances

Data frame of worker instance information.

id

Integer worker ID from the last call to settings().

async

A crew_async() object to run low-level launcher tasks asynchronously.

throttle

A crew_throttle() object to throttle scaling.

Methods


Method new()

Launcher constructor.

Usage

crew_class_launcher$new(
  name = NULL,
  workers = NULL,
  seconds_interval = NULL,
  seconds_timeout = NULL,
  seconds_launch = NULL,
  seconds_idle = NULL,
  seconds_wall = NULL,
  seconds_exit = NULL,
  tasks_max = NULL,
  tasks_timers = NULL,
  reset_globals = NULL,
  reset_packages = NULL,
  reset_options = NULL,
  garbage_collection = NULL,
  crashes_error = NULL,
  launch_max = NULL,
  tls = NULL,
  processes = NULL,
  r_arguments = NULL,
  options_metrics = NULL
)

Arguments

name

See crew_launcher().

workers

See crew_launcher().

seconds_interval

See crew_launcher().

seconds_timeout

See crew_launcher().

seconds_launch

See crew_launcher().

seconds_idle

See crew_launcher().

seconds_wall

See crew_launcher().

seconds_exit

See crew_launcher().

tasks_max

See crew_launcher().

tasks_timers

See crew_launcher().

reset_globals

See crew_launcher().

reset_packages

See crew_launcher().

reset_options

See crew_launcher().

garbage_collection

See crew_launcher().

crashes_error

See crew_launcher().

launch_max

Deprecated.

tls

See crew_launcher().

processes

See crew_launcher().

r_arguments

See crew_launcher().

options_metrics

See crew_launcher().

Returns

An R6 object with the launcher.

Examples

if (identical(Sys.getenv("CREW_EXAMPLES"), "true")) {
client <- crew_client()
client$start()
launcher <- crew_launcher_local()
launcher$start(url = client$url, profile = client$profile)
launcher$launch()
task <- mirai::mirai("result", .compute = client$profile)
mirai::call_mirai_(task)
task$data
client$terminate()
}


Method validate()

Validate the launcher.

Usage

crew_class_launcher$validate()

Returns

NULL (invisibly).


Method poll()

Poll the throttle.

Usage

crew_class_launcher$poll()

Returns

TRUE to run whatever work comes next, FALSE to skip until the appropriate time.


Method settings()

List of arguments for mirai::daemon().

Usage

crew_class_launcher$settings()

Returns

List of arguments for mirai::daemon().


Method call()

Create a call to crew_worker() to help create custom launchers.

Usage

crew_class_launcher$call(
  worker,
  socket = NULL,
  launcher = NULL,
  instance = NULL
)

Arguments

worker

Character string, name of the worker.

socket

Deprecated on 2025-01-28 (crew version 1.0.0).

launcher

Deprecated on 2025-01-28 (crew version 1.0.0).

instance

Deprecated on 2025-01-28 (crew version 1.0.0).

Returns

Character string with a call to crew_worker().

Examples

launcher <- crew_launcher_local()
launcher$start(url = "tcp://127.0.0.1:57000", profile = "profile")
launcher$call(worker = "worker_name")
launcher$terminate()


Method start()

Start the launcher.

Usage

crew_class_launcher$start(url = NULL, profile = NULL, sockets = NULL)

Arguments

url

Character string, websocket URL for worker connections.

profile

Character string, mirai compute profile.

sockets

Deprecated on 2025-01-28 (crew version 1.0.0).

Returns

NULL (invisibly).


Method terminate()

Terminate the whole launcher, including all workers.

Usage

crew_class_launcher$terminate()

Returns

NULL (invisibly).


Method resolve()

Resolve asynchronous worker submissions.

Usage

crew_class_launcher$resolve()

Returns

NULL (invisibly). Throw an error if there were any asynchronous worker submission errors.'


Method update()

Update worker metadata, resolve asynchronous worker submissions, and terminate lost workers.

Usage

crew_class_launcher$update(status)

Arguments

status

A mirai status list.

Returns

NULL (invisibly).


Method launch()

Launch a worker.

Usage

crew_class_launcher$launch()

Returns

Handle of the launched worker.


Method scale()

Auto-scale workers out to meet the demand of tasks.

Usage

crew_class_launcher$scale(status, throttle = NULL)

Arguments

status

A mirai status list with worker and task information.

throttle

Deprecated, only used in the controller as of 2025-01-16 (crew version 0.10.2.9003).

Returns

Invisibly returns TRUE if there was any relevant auto-scaling activity (new worker launches or worker connection/disconnection events) (FALSE otherwise).


Method launch_worker()

Abstract worker launch method.

Usage

crew_class_launcher$launch_worker(call, name, launcher, worker)

Arguments

call

Character of length 1 with a namespaced call to crew_worker() which will run in the worker and accept tasks.

name

Character of length 1 with an informative worker name.

launcher

Character of length 1, name of the launcher.

worker

Positive integer of length 1, index of the worker. This worker index remains the same even when the current instance of the worker exits and a new instance launches. It is always between 1 and the maximum number of concurrent workers.

Details

Launcher plugins will overwrite this method.

Returns

A handle to mock the worker launch.


Method terminate_worker()

Abstract worker termination method.

Usage

crew_class_launcher$terminate_worker(handle)

Arguments

handle

A handle object previously returned by launch_worker() which allows the termination of the worker.

Details

Launcher plugins will overwrite this method.

Returns

A handle to mock worker termination.


Method terminate_workers()

Terminate all workers.

Usage

crew_class_launcher$terminate_workers()

Returns

NULL (invisibly).


Method crashes()

Deprecated on 2025-01-28 (crew version 1.0.0).

Usage

crew_class_launcher$crashes(index = NULL)

Arguments

index

Unused argument.

Returns

The integer 1, for compatibility.


Method set_name()

Deprecated on 2025-01-28 (crew version 1.0.0).

Usage

crew_class_launcher$set_name(name)

Arguments

name

Name to set for the launcher.

Returns

NULL (invisibly).

Examples

if (identical(Sys.getenv("CREW_EXAMPLES"), "true")) {
client <- crew_client()
client$start()
launcher <- crew_launcher_local()
launcher$start(url = client$url, profile = client$profile)
launcher$launch()
task <- mirai::mirai("result", .compute = client$profile)
mirai::call_mirai_(task)
task$data
client$terminate()
}

## ------------------------------------------------
## Method `crew_class_launcher$new`
## ------------------------------------------------

if (identical(Sys.getenv("CREW_EXAMPLES"), "true")) {
client <- crew_client()
client$start()
launcher <- crew_launcher_local()
launcher$start(url = client$url, profile = client$profile)
launcher$launch()
task <- mirai::mirai("result", .compute = client$profile)
mirai::call_mirai_(task)
task$data
client$terminate()
}

## ------------------------------------------------
## Method `crew_class_launcher$call`
## ------------------------------------------------

launcher <- crew_launcher_local()
launcher$start(url = "tcp://127.0.0.1:57000", profile = "profile")
launcher$call(worker = "worker_name")
#> [1] "crew::crew_worker(settings = list(url = \"tcp://127.0.0.1:57000\", dispatcher = TRUE, asyncdial = FALSE, autoexit = 15L, cleanup = 1L, output = TRUE, maxtasks = Inf, idletime = Inf, walltime = Inf, timerstart = 0L, id = 1L, tls = NULL, rs = NULL), launcher = \"b8cb73c4\", worker = \"worker_name\", options_metrics = crew::crew_options_metrics(path = NULL, seconds_interval = 5))"
launcher$terminate()