Skip to content

Commit ea6e89e

Browse files
committed
Workbench launcher concept
1 parent 1326204 commit ea6e89e

File tree

5 files changed

+80
-1
lines changed

5 files changed

+80
-1
lines changed

DESCRIPTION

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ Imports:
3030
nanonext (>= 1.6.2.9002)
3131
Suggests:
3232
cli,
33-
litedown
33+
litedown,
34+
rstudioapi
3435
Enhances:
3536
parallel,
3637
promises

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ export(stop_cluster)
6060
export(stop_mirai)
6161
export(unresolved)
6262
export(with_daemons)
63+
export(workbench_config)
6364
importFrom(nanonext,"opt<-")
6465
importFrom(nanonext,.advance)
6566
importFrom(nanonext,.context)

R/launchers.R

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,23 @@ launch_remote <- function(n = 1L, remote = remote_config(), ..., tls = NULL, .co
9494
dots <- if (...length()) parse_dots(envir, ...) else envir[["dots"]]
9595
if (is.null(tls)) tls <- envir[["tls"]]
9696

97+
if (length(remote) == 2L) {
98+
requireNamespace("rstudioapi", quietly = TRUE) || stop(._[["rstudio_api"]])
99+
rstudioapi::launcherAvailable()
100+
cluster <- remote[["name"]]
101+
container <- rstudioapi::launcherContainer(remote[["image"]])
102+
lapply(
103+
seq_len(n),
104+
function(x) rstudioapi::launcherSubmitJob(
105+
sprintf("mirai_daemon_%d", x),
106+
cluster = cluster,
107+
command = launch_remote(),
108+
container = container
109+
)
110+
)
111+
return(invisible())
112+
}
113+
97114
command <- remote[["command"]]
98115
rscript <- remote[["rscript"]]
99116
quote <- remote[["quote"]]
@@ -392,6 +409,34 @@ cluster_config <- function(command = "sbatch", options = "", rscript = "Rscript"
392409
list(command = "/bin/sh", args = args, rscript = rscript, quote = NULL)
393410
}
394411

412+
#' Workbench Remote Launch Configuration
413+
#'
414+
#' Generates a remote configuration for launching daemons using the default
415+
#' launcher configured in Posit Workbench.
416+
#'
417+
#' @inherit remote_config return
418+
#'
419+
#' @seealso [ssh_config()], [cluster_config()], and [remote_config()] for other
420+
#' remote launch configurations.
421+
#'
422+
#' @examples
423+
#' tryCatch(workbench_config(), error = identity)
424+
#'
425+
#' \dontrun{
426+
#'
427+
#' # Launch 2 daemons using the Workbench default launcher:
428+
#' daemons(n = 2, url = host_url(), remote = workbench_config())
429+
#' }
430+
#'
431+
#' @export
432+
#'
433+
workbench_config <- function() {
434+
requireNamespace("rstudioapi", quietly = TRUE) || stop(._[["rstudio_api"]])
435+
rstudioapi::launcherAvailable()
436+
cluster <- rstudioapi::launcherGetInfo()[["clusters"]][[1L]]
437+
list(name = cluster[["name"]], image = cluster[["defaultImage"]])
438+
}
439+
395440
#' URL Constructors
396441
#'
397442
#' `host_url()` constructs a valid host URL (at which daemons may connect) based

R/mirai-package.R

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@
8080
n_zero = "the number of daemons must be zero or greater",
8181
not_found = "compute profile `%s` not found",
8282
numeric_n = "`n` must be numeric, did you mean to provide `url`?",
83+
rstudio_api = "workbench launcher requires the `rstudioapi` package",
84+
rstudio_unavailable = "workbench launcher requires a compatible environment",
8385
sync_daemons = "mirai: initial sync with daemon(s) [%d secs elapsed]",
8486
sync_dispatcher = "mirai: initial sync with dispatcher [%d secs elapsed]",
8587
within_map = "cannot create local daemons from within mirai map"

man/workbench_config.Rd

Lines changed: 30 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)