-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from mrc-ide/mrc-5114
Mrc 5114 Add a submit function to the queue object
- Loading branch information
Showing
13 changed files
with
290 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,7 @@ Imports: | |
porcelain, | ||
R6, | ||
redux, | ||
rrq, | ||
rrq (>= 0.7.15), | ||
withr | ||
Suggests: | ||
fs, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
runner_run <- function(orderly_root, reportname, parameters, branch, ref, ...) { | ||
# Setup | ||
worker_id <- Sys.getenv("RRQ_WORKER_ID") | ||
worker_path <- file.path(orderly_root, ".packit", "workers", worker_id) | ||
point_head_to_ref(worker_path, branch, ref) | ||
|
||
# Initial cleanup | ||
git_clean(worker_path) | ||
|
||
# Run | ||
withr::with_envvar( | ||
c(ORDERLY_SRC_ROOT = file.path(worker_path, "src", reportname)), | ||
orderly2::orderly_run(reportname, parameters = parameters, | ||
root = orderly_root, ...) | ||
) | ||
|
||
# Cleanup | ||
git_clean(worker_path) | ||
} | ||
|
||
point_head_to_ref <- function(worker_path, branch, ref) { | ||
gert::git_fetch(repo = worker_path) | ||
gert::git_branch_checkout(branch, repo = worker_path) | ||
gert::git_reset_hard(ref, repo = worker_path) | ||
} | ||
|
||
add_dir_parent_if_empty <- function(files_to_delete, path) { | ||
contained_files <- list.files(path, full.names = TRUE) | ||
if (length(setdiff(contained_files, files_to_delete)) > 0) { | ||
return(files_to_delete) | ||
} | ||
add_dir_parent_if_empty(c(files_to_delete, path), dirname(path)) | ||
} | ||
|
||
get_empty_dirs <- function(worker_path) { | ||
dirs <- fs::dir_ls(worker_path, recurse = TRUE, type = "directory") | ||
Reduce(add_dir_parent_if_empty, c(list(character()), dirs)) | ||
} | ||
|
||
git_clean <- function(worker_path) { | ||
# gert does not have git clean but this should achieve the same thing | ||
tryCatch( | ||
{ | ||
gert::git_stash_save( | ||
include_untracked = TRUE, | ||
include_ignored = TRUE, | ||
repo = worker_path | ||
) | ||
gert::git_stash_drop(repo = worker_path) | ||
}, | ||
error = function(e) { | ||
# we don't need to rethrow the error here since it doesn't break any | ||
# further report runs | ||
if (e$message != "cannot stash changes - there is nothing to stash.") { | ||
# TODO add logger here | ||
message(e$message) | ||
} | ||
NULL | ||
} | ||
) | ||
# however git ignores all directories, only cares about files, so we may | ||
# have empty directories left | ||
unlink(get_empty_dirs(worker_path), recursive = TRUE) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
orderly2::orderly_artefact("Some data", "data.rds") | ||
d <- data.frame(a = 1:10, x = runif(10), y = 1:10 + runif(10)) | ||
write.table("test", file = file.path("..", "..", "inside_draft.txt")) | ||
write.table("test", file = file.path("..", "..", "..", "outside_draft.txt")) | ||
saveRDS(d, "data.rds") |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,7 @@ new_queue_quietly <- function(root, ...) { | |
start_queue_workers_quietly <- function(n_workers, | ||
controller, env = parent.frame()) { | ||
suppressMessages( | ||
rrq::rrq_worker_spawn2(n_workers, controller = controller) | ||
rrq::rrq_worker_spawn(n_workers, controller = controller) | ||
) | ||
withr::defer(rrq::rrq_worker_stop(controller = controller), env = env) | ||
} | ||
|
@@ -67,15 +67,65 @@ copy_examples <- function(examples, path_src) { | |
} | ||
|
||
|
||
helper_add_git <- function(path) { | ||
helper_add_git <- function(path, add = ".") { | ||
gert::git_init(path) | ||
sha <- git_add_and_commit(path) | ||
sha <- git_add_and_commit(path, add) | ||
branch <- gert::git_branch(repo = path) | ||
url <- "https://example.com/git" | ||
gert::git_remote_add(url, repo = path) | ||
list(path = path, branch = branch, sha = sha, url = url) | ||
} | ||
|
||
new_queue_quietly <- function(root, ...) { | ||
suppressMessages(Queue$new(root, ...)) | ||
} | ||
|
||
make_worker_dirs <- function(orderly_root, ids) { | ||
packit_path <- file.path(orderly_root, ".packit") | ||
dir.create(packit_path) | ||
workers <- file.path(packit_path, "workers") | ||
dir.create(workers) | ||
lapply(ids, function(id) { | ||
worker_path <- file.path(workers, id) | ||
dir.create(worker_path) | ||
gert::git_clone(orderly_root, path = worker_path) | ||
gert::git_config_set("user.name", id, repo = worker_path) | ||
gert::git_config_set("user.email", id, repo = worker_path) | ||
}) | ||
|
||
} | ||
|
||
start_queue_workers_quietly <- function(n_workers, | ||
controller, env = parent.frame()) { | ||
worker_manager <- suppressMessages( | ||
rrq::rrq_worker_spawn(n_workers, controller = controller) | ||
) | ||
withr::defer(rrq::rrq_worker_stop(controller = controller), env = env) | ||
worker_manager | ||
} | ||
|
||
start_queue_with_workers <- function(root, n_workers, env = parent.frame()) { | ||
q <- new_queue_quietly(root) | ||
worker_manager <- start_queue_workers_quietly(n_workers, q$controller, | ||
env = env) | ||
make_worker_dirs(root, worker_manager$id) | ||
q | ||
} | ||
|
||
skip_if_no_redis <- function() { | ||
available <- redux::redis_available() | ||
if (!available) { | ||
testthat::skip("Skipping test as redis is not available") | ||
} | ||
invisible(available) | ||
} | ||
|
||
expect_worker_task_complete <- function(task_id, controller, n_tries) { | ||
is_task_successful <- rrq::rrq_task_wait( | ||
task_id, controller = controller, timeout = n_tries | ||
) | ||
expect_true(is_task_successful) | ||
} | ||
|
||
initialise_git_repo <- function() { | ||
t <- tempfile() | ||
|
@@ -85,16 +135,25 @@ initialise_git_repo <- function() { | |
} | ||
|
||
|
||
git_add_and_commit <- function(path) { | ||
gert::git_add(".", repo = path) | ||
create_new_commit <- function(path, new_file = "new", message = "new message", | ||
add = ".") { | ||
writeLines("new file", file.path(path, new_file)) | ||
gert::git_add(add, repo = path) | ||
user <- "author <[email protected]>" | ||
gert::git_commit("new commit", author = user, committer = user, repo = path) | ||
} | ||
|
||
|
||
git_add_and_commit <- function(path, add = ".") { | ||
gert::git_add(add, repo = path) | ||
user <- "author <[email protected]>" | ||
gert::git_commit("new commit", author = user, committer = user, repo = path) | ||
} | ||
|
||
|
||
create_new_commit <- function(path, new_file = "new") { | ||
create_new_commit <- function(path, new_file = "new", add = ".") { | ||
writeLines("new file", file.path(path, new_file)) | ||
git_add_and_commit(path) | ||
git_add_and_commit(path, add) | ||
} | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.