Skip to content

Commit

Permalink
ping server until it's started up properly
Browse files Browse the repository at this point in the history
  • Loading branch information
Ellpeck committed Oct 7, 2024
1 parent 9043d9c commit 20eade2
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ Imports:
bslib,
miniUI,
rstudioapi,
flowr
flowr,
pingr
Remotes:
flowr=github::flowr-analysis/flowr-r-adapter
License: GPL-3 + file LICENSE
Expand Down
6 changes: 3 additions & 3 deletions R/node.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#' @export
install_node_addin <- function() {
base <- node_base_dir()
print(paste0("Installing Node.js and flowR Shell in ", base))
cat(paste0("Installing Node.js and flowR Shell in ", base, "\n"))
node_ver <- read_flowr_pref(pref_node_version, default_node_version)
assure_valid_semver(node_ver)
flowr_ver <- read_flowr_pref(pref_flowr_version, default_flowr_version)
Expand All @@ -14,9 +14,9 @@ install_node_addin <- function() {
flowr::install_flowr(flowr_ver, TRUE, base)
# check if the flowr namespace exists
if ("flowr" %in% rownames(utils::installed.packages())) {
print("Successfully installed Node.js and flowR Shell")
cat("Successfully installed Node.js and flowR Shell\n")
} else {
stop("Failed to install flowR. Please check the R console for more information.")
stop("Failed to install flowR. Please check the R console for more information.\n")
}
},
error = function(e) {
Expand Down
14 changes: 11 additions & 3 deletions R/shell.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,18 @@ make_flowr_session_storage <- function() {
return()
}
cat(paste0("[flowR] Starting local flowR server with pid ", pid, "\n"))
# wait until the server has started up
waited <- 0
while (waited < 30 && is.na(sys::exec_status(pid, FALSE))) {
Sys.sleep(1)
waited <- waited + 1
cat(paste0("Waiting for flowR server to start up (", waited, "s)\n"))
if (!is.na(pingr::ping_port(default_server_host, default_server_port, count = 1))) {
break
}
}
host <- default_server_host
port <- default_server_port
# sleep a bit until the server has fully started up
Sys.sleep(5)
} else {
# connect externally
cat("[flowR] Connecting to flowR server\n")
Expand All @@ -65,7 +73,7 @@ make_flowr_session_storage <- function() {
stop(paste0("[flowR] Failed to connect to flowR server at ", host, ":", port, ": ", e))
}
)
print(conn_hello[[2]])
cat(paste0(conn_hello[[2]], "\n"))
connection <<- conn_hello[[1]]
} else {
cat("[flowR] flowR server already connected\n")
Expand Down
2 changes: 1 addition & 1 deletion R/slice.R
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,6 @@ slice_addin <- function() {
reconstruct_addin <- function() {
result <- slice_addin()
code <- result$results$reconstruct$code
cat(paste0("[flowR] Showing reconstruct view"))
cat(paste0("[flowR] Showing reconstruct view\n"))
display_code(if(is.null(code)) "No reconstructed code available" else code)
}

0 comments on commit 20eade2

Please sign in to comment.