Skip to content

Commit a86aef4

Browse files
committed
Workbench launcher concept
1 parent cf8f9d7 commit a86aef4

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)
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
@@ -58,6 +58,7 @@ export(status)
5858
export(stop_cluster)
5959
export(stop_mirai)
6060
export(unresolved)
61+
export(workbench_config)
6162
importFrom(nanonext,"opt<-")
6263
importFrom(nanonext,.advance)
6364
importFrom(nanonext,.context)

R/launchers.R

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,23 @@ launch_remote <- function(
108108
dots <- if (missing(..1)) envir[["dots"]] else parse_dots(...)
109109
if (is.null(tls)) tls <- envir[["tls"]]
110110

111+
if (length(remote) == 2L) {
112+
requireNamespace("rstudioapi", quietly = TRUE) || stop(._[["rstudio_api"]])
113+
rstudioapi::launcherAvailable()
114+
cluster <- remote[["name"]]
115+
container <- rstudioapi::launcherContainer(remote[["image"]])
116+
lapply(
117+
seq_len(n),
118+
function(x) rstudioapi::launcherSubmitJob(
119+
sprintf("mirai_daemon_%d", x),
120+
cluster = cluster,
121+
command = launch_remote(),
122+
container = container
123+
)
124+
)
125+
return(invisible())
126+
}
127+
111128
command <- remote[["command"]]
112129
rscript <- remote[["rscript"]]
113130
quote <- remote[["quote"]]
@@ -431,6 +448,34 @@ cluster_config <- function(
431448
list(command = "/bin/sh", args = args, rscript = rscript, quote = NULL)
432449
}
433450

451+
#' Workbench Remote Launch Configuration
452+
#'
453+
#' Generates a remote configuration for launching daemons using the default
454+
#' launcher configured in Posit Workbench.
455+
#'
456+
#' @inherit remote_config return
457+
#'
458+
#' @seealso [ssh_config()], [cluster_config()], and [remote_config()] for other
459+
#' remote launch configurations.
460+
#'
461+
#' @examples
462+
#' tryCatch(workbench_config(), error = identity)
463+
#'
464+
#' \dontrun{
465+
#'
466+
#' # Launch 2 daemons using the Workbench default launcher:
467+
#' daemons(n = 2, url = host_url(), remote = workbench_config())
468+
#' }
469+
#'
470+
#' @export
471+
#'
472+
workbench_config <- function() {
473+
requireNamespace("rstudioapi", quietly = TRUE) || stop(._[["rstudio_api"]])
474+
rstudioapi::launcherAvailable()
475+
cluster <- rstudioapi::launcherGetInfo()[["clusters"]][[1L]]
476+
list(name = cluster[["name"]], image = cluster[["defaultImage"]])
477+
}
478+
434479
#' URL Constructors
435480
#'
436481
#' `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
@@ -83,6 +83,8 @@
8383
n_zero = "the number of daemons must be zero or greater",
8484
not_found = "compute profile `%s` not found",
8585
numeric_n = "`n` must be numeric, did you mean to provide `url`?",
86+
rstudio_api = "workbench launcher requires the `rstudioapi` package",
87+
rstudio_unavailable = "workbench launcher requires a compatible environment",
8688
sync_daemons = "mirai: initial sync with daemon(s) [%d secs elapsed]",
8789
sync_dispatcher = "mirai: initial sync with dispatcher [%d secs elapsed]",
8890
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)