Skip to content

Commit

Permalink
Minor fix
Browse files Browse the repository at this point in the history
- Silence the NOTE!
- config port n = 100
- Fix kill_runner wrong arg
  • Loading branch information
ElianHugh committed Jun 23, 2024
1 parent 6bfe2be commit ac10f2c
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 17 deletions.
4 changes: 2 additions & 2 deletions R/cli.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cli_welcome <- function() {
v <- utils::packageVersion("hotwater")
v <- utils::packageVersion("hotwater") # nolint: object_usage_linter.
cli::cli_h1("{.pkg hotwater} v{v}")
}

Expand All @@ -8,7 +8,7 @@ cli_goodbye <- function() {
}

cli_watching_directory <- function(engine) {
dirs <- c(engine$config$entry_dir, engine$config$dirs)
dirs <- c(engine$config$entry_dir, engine$config$dirs) # nolint: object_usage_linter.
cli::cli_inform("Watching {.file {dirs}} for changes...")
}

Expand Down
4 changes: 2 additions & 2 deletions R/config.R
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ validate_config <- function(config) {
new_port <- function(used, host = "127.0.0.1") {
out <- NULL
if (missing(used)) {
out <- httpuv::randomPort(host = host)
out <- httpuv::randomPort(host = host, n = 100L)
} else {
repeat {
out <- httpuv::randomPort(host = host)
out <- httpuv::randomPort(host = host, n = 100L)
if (out != used) break
}
}
Expand Down
31 changes: 20 additions & 11 deletions R/mirai.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,34 @@ new_runner <- function(engine) {
output = TRUE,
.compute = engine$config$runner_compute
)

port <- engine$config$port
path <- engine$config$entry_path
mdware <- middleware(engine)
mod <- file.path(getwd(), engine$config$entry_path)
host <- engine$config$host

engine$runner <- mirai::mirai(
{
if (requireNamespace("box", quietly = TRUE)) {
box::set_script_path(mod) # nolint: object_usage_linter.
box::set_script_path(mod)
}
plumber::pr(path) |> # nolint: object_usage_linter.
middleware() |>
plumber::pr(path) |>
mdware() |>
plumber::pr_run(
port = port, # nolint: object_usage_linter.
host = host, # nolint: object_usage_linter.
port = port,
host = host,
quiet = TRUE,
debug = TRUE
)
},
port = engine$config$port,
path = engine$config$entry_path,
host = engine$config$host,
middleware = middleware(engine),
mod = file.path(getwd(), engine$config$entry_path),
.args = list(
port = port,
path = path,
host = host,
mdware = mdware,
mod = mod
),
.compute = engine$config$runner_compute
)

Expand All @@ -47,7 +56,7 @@ new_runner <- function(engine) {

kill_runner <- function(engine) {
mirai::daemons(0L, .compute = engine$config$runner_compute)
!is_runner_alive(engine$runner)
!is_runner_alive(engine)
}

is_runner_alive <- function(engine) {
Expand Down
4 changes: 2 additions & 2 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@

- The CLI messages are a bit all over the place, and errors don't always cause the progress bar to fail

## 5
## 6

- Fix some global binding notes
- Should do some defensive prog
1 change: 1 addition & 0 deletions tests/testthat/test-engine.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ test_that("engine reuse", {
test_that("can kill engine", {
engine <- new_test_engine()
new_runner(engine)
expect_true(is_runner_alive(engine))
kill_engine(engine)
expect_false(is_runner_alive(engine))
cleanup_test_engine(engine)
Expand Down

0 comments on commit ac10f2c

Please sign in to comment.