Skip to content

Commit

Permalink
feat: add logs_dir as inout to queue
Browse files Browse the repository at this point in the history
  • Loading branch information
absternator committed Aug 19, 2024
1 parent 1e037aa commit d781a99
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,3 @@ docs
.valgrind_ignore
inst/doc
pkgdown
logs
8 changes: 4 additions & 4 deletions R/queue.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ Queue <- R6::R6Class("Queue", # nolint
#' @param root Orderly root.
#' @param queue_id ID of an existing queue to connect to, creates a new one
#' if NULL (default NULL)
initialize = function(root, queue_id = NULL) {
#' @param logs_dir directory to store worker logs
initialize = function(root, queue_id = NULL, logs_dir = "logs/worker") {
self$root <- root
self$config <- orderly2::orderly_config(self$root)
if (!runner_has_git(self$root)) {
Expand All @@ -35,9 +36,8 @@ Queue <- R6::R6Class("Queue", # nolint
queue_id %||% orderly_queue_id(),
con = con
)
log_dir_name <- "logs/worker"
dir.create(log_dir_name, showWarnings = FALSE)
worker_config <- rrq::rrq_worker_config(heartbeat_period = 10, logdir = log_dir_name)
dir.create(logs_dir, showWarnings = FALSE)
worker_config <- rrq::rrq_worker_config(heartbeat_period = 10, logdir = logs_dir)
rrq::rrq_worker_config_save("localhost", worker_config,
controller = self$controller
)
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/helper-orderly-runner.R
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ start_queue_workers_quietly <- function(n_workers,
start_queue_with_workers <- function(
root, n_workers, env = parent.frame(), queue_id = NULL
) {
q <- new_queue_quietly(root, queue_id = queue_id)
q <- new_queue_quietly(root, queue_id = queue_id, logs_dir = tempfile())
worker_manager <- start_queue_workers_quietly(n_workers, q$controller,
env = env)
make_worker_dirs(root, worker_manager$id)
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-api.R
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ test_that("can run orderly reports", {
gert::git_init(repo)
orderly2::orderly_gitignore_update("(root)", root = repo)
git_add_and_commit(repo)
queue <- Queue$new(repo, queue_id = queue_id)
queue <- Queue$new(repo, queue_id = queue_id, logs_dir = tempfile())
worker_manager <- start_queue_workers_quietly(
1, queue$controller
)
Expand Down
7 changes: 4 additions & 3 deletions tests/testthat/test-queue.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ test_that("creates directory for logs & adds to worker config", {

root <- create_temporary_root(use_file_store = TRUE)
gert::git_init(root)
q <- new_queue_quietly(root)
expect_true(dir.exists("logs/worker"))
expect_equal("logs/worker", rrq::rrq_worker_config_read("localhost", controller = q$controller)$logdir)
logs_dir <- tempfile()
q <- new_queue_quietly(root, logs_dir = logs_dir)
expect_true(dir.exists(logs_dir))
expect_equal(logs_dir, rrq::rrq_worker_config_read("localhost", controller = q$controller)$logdir)
})

test_that("Errors if not git repo", {
Expand Down

0 comments on commit d781a99

Please sign in to comment.