Skip to content

Commit

Permalink
Merge pull request #21 from A2-ai/timer_bug
Browse files Browse the repository at this point in the history
Timer bug
  • Loading branch information
jenna-a2ai authored Dec 11, 2024
2 parents ade0d77 + 0e6ea11 commit ac3c316
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 8 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: ghqc
Title: Manage QC via GitHub Issues using Shiny Apps
Version: 0.2.0
Version: 0.2.1
Authors@R: c(
person("Anne", "Zheng", email = "[email protected]", role = c("aut")),
person("Jenna", "Johnson", email = "[email protected]", role = c("aut")),
Expand Down
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# ghqc 0.2.1

- increases counter for starting up shiny apps
- adds waiter to console while app is starting up

# ghqc 0.2.0

- Updated the custom configuration options repository (now `GHQC_OPTIONS_REPO`) check to reflect the following changes:
Expand Down
42 changes: 35 additions & 7 deletions R/helper.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ is_shiny_ready <- function(url) {
} # is_shiny_ready

#' @importFrom httpuv randomPort
#' @importFrom rstudioapi jobRunScript
#' @importFrom rstudioapi viewer
#' @importFrom rstudioapi jobRunScript jobGetState viewer
#' @importFrom fs file_exists
#' @importFrom withr defer
run_app <- function(app_name, qc_dir, lib_path, config_path) {
Expand All @@ -52,7 +51,6 @@ run_app <- function(app_name, qc_dir, lib_path, config_path) {
lib_path = lib_path,
config_path = config_path
)
#browser()

# needed a way to create a temp file that would ran in a background job in the qc dir
# the script needed to point towards the ghqc libpaths, load the package, and run the app
Expand Down Expand Up @@ -98,19 +96,49 @@ run_app <- function(app_name, qc_dir, lib_path, config_path) {
url <- sprintf("http://127.0.0.1:%s", port)


# new_rstudioapi is true if its >= 0.16.0
new_rstudioapi <- compareVersion(utils::packageDescription("rstudioapi", fields = "Version"), "0.16.0") != -1

sp1 <- cli::make_spinner()
cli::cli_inform("Waiting for shiny app to start...")

total_time <- 35 # Total wait time in seconds
interval <- 0.1 # Spinner refresh interval in seconds
iterations <- total_time / interval # Total iterations needed
counter <- 1
while(counter < 20) {
while(counter <= iterations) {
sp1$spin()
if (is_shiny_ready(url)) {
cli::cli_inform("Shiny app started")
sp1$finish()
cli_alert_success("Shiny app started")
break
}

# if rstudioapi is >= 0.16.0, can use jobGetState to check if there's been an error in the bgj
if (new_rstudioapi) {
if (rstudioapi::jobGetState(job_id) == "failed") {
sp1$finish()
cli::cli_alert_danger("Shiny app could not be started due to error (see Background Jobs panel)")
break
}
}

counter <- counter + 1
Sys.sleep(1)
Sys.sleep(interval)
}
if (counter > 19) cli::cli_alert_danger("Shiny app could not be started due to timeout or error")

# check if there was a timeout
if (counter > iterations) {
sp1$finish()

# if rstudio api is newer, it caught it earlier in the case of an error, so it's definitely a timeout
if (new_rstudioapi) {
cli::cli_alert_danger("Shiny app could not be started due to timeout")
}
else { # else, was either a timeout or error
cli::cli_alert_danger("Shiny app could not be started due to timeout or error")
}
}

rstudioapi::viewer(url)
}, error = function(e){
Expand Down

0 comments on commit ac3c316

Please sign in to comment.