Skip to content

Commit 54fab75

Browse files
committed
Refactor a bit
1 parent dd834ff commit 54fab75

File tree

1 file changed

+21
-20
lines changed

1 file changed

+21
-20
lines changed

R/launchers.R

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -99,26 +99,10 @@ launch_remote <- function(n = 1L, remote = remote_config(), ..., tls = NULL, .co
9999
if (length(remote) == 2L) {
100100
platform <- remote[["platform"]]
101101
args <- remote[["args"]]
102-
platform == "posit" && {
103-
tools <- posit_tools()
104-
is.environment(tools) || stop(._[["posit_api"]])
105-
submit_job <- .subset2(tools, ".rs.api.launcher.submitJob")
106-
new_container <- .subset2(tools, ".rs.api.launcher.newContainer")
107-
cluster <- args[["name"]]
108-
container <- new_container(args[["image"]])
109-
cmds <- launch_remote(n)
110-
lapply(
111-
cmds,
112-
function(cmd) submit_job(
113-
sprintf("mirai_daemon_%s", random(3L)),
114-
cluster = cluster,
115-
command = cmd,
116-
container = container
117-
)
118-
)
119-
return(cmds)
120-
}
121-
stop(._[["platform_unsupported"]])
102+
platform != "posit" && stop(._[["platform_unsupported"]])
103+
tools <- posit_tools()
104+
is.environment(tools) || stop(._[["posit_api"]])
105+
return(posit_workbench_launch(n, args, tools))
122106
}
123107

124108
command <- remote[["command"]]
@@ -553,3 +537,20 @@ posit_tools <- function() {
553537
is.function(feature_available) && feature_available() || return()
554538
tools
555539
}
540+
541+
posit_workbench_launch <- function(n, args, tools) {
542+
submit_job <- .subset2(tools, ".rs.api.launcher.submitJob")
543+
new_container <- .subset2(tools, ".rs.api.launcher.newContainer")
544+
cluster <- args[["name"]]
545+
container <- new_container(args[["image"]])
546+
cmds <- launch_remote(n)
547+
lapply(cmds, function(cmd)
548+
submit_job(
549+
sprintf("mirai_daemon_%s", random(3L)),
550+
cluster = cluster,
551+
command = cmd,
552+
container = container
553+
)
554+
)
555+
cmds
556+
}

0 commit comments

Comments
 (0)