Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
* Fixed documentation regarding `store.job.collection` behavior in `makeClusterFunctions()` (#333, @n3orma)
* Fixed `reduceResults()` passing the wrong `job` to `fun` when `init` is omitted: result `i + 1` was paired with job `i` (#336, @chenyangsu).
* Fixed `Worker` (used by `makeClusterFunctionsSSH()`) failing on registry paths containing spaces.
* The "Work dir does not exist" error now includes the missing directory and the node name (#260).
* `getLog()` gains argument `missing.as.empty` to return an empty character vector instead of an error if the log file is missing (#239).
* Fixed `getLog()` and `showLog()` failing with "cannot open the connection" instead of reporting a missing log file if `fs.latency` is 0.

# batchtools 0.9.18

Expand Down
15 changes: 11 additions & 4 deletions R/Logs.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#' @useDynLib batchtools fill_gaps
readLog = function(id, missing.as.empty = FALSE, reg = getDefaultRegistry()) {
log.file = getLogFiles(reg, id)
if (is.na(log.file) || !waitForFile(log.file, timeout = reg$cluster.functions$fs.latency, must.work = FALSE)) {
# waitForFile() returns TRUE without checking if fs.latency is 0
fs.latency = reg$cluster.functions$fs.latency
if (is.na(log.file) || !(fs::file_exists(log.file) || (fs.latency > 0 && waitForFile(log.file, timeout = fs.latency, must.work = FALSE)))) {
if (missing.as.empty)
return(data.table(job.id = integer(0L), lines = character(0L)))
stopf("Log file '%s' for job with id %i not available", log.file, id$job.id)
Expand Down Expand Up @@ -82,9 +84,13 @@ grepLogs = function(ids = NULL, pattern, ignore.case = FALSE, fixed = FALSE, reg
#' \code{getLog} returns the log as character vector.
#' @template id
#' @template reg
#' @param missing.as.empty [\code{logical(1)}]\cr
#' Only used by \code{getLog}.
#' If \code{TRUE}, return an empty character vector if the log file does not exist (yet).
#' Default is \code{FALSE}, which throws an error.
#' @export
#' @family debug
#' @return Nothing.
#' @return \code{showLog} returns nothing, \code{getLog} a character vector of log lines.
#' @examples
#' \dontshow{ batchtools:::example_push_temp(1) }
#' tmp = makeRegistry(file.dir = NA, make.default = FALSE)
Expand Down Expand Up @@ -116,8 +122,9 @@ showLog = function(id, reg = getDefaultRegistry()) {

#' @export
#' @rdname showLog
getLog = function(id, reg = getDefaultRegistry()) {
getLog = function(id, reg = getDefaultRegistry(), missing.as.empty = FALSE) {
assertRegistry(reg, sync = TRUE)
assertFlag(missing.as.empty)
id = convertId(reg, id)
extractLog(readLog(id, reg = reg), id)
extractLog(readLog(id, missing.as.empty = missing.as.empty, reg = reg), id)
}
2 changes: 1 addition & 1 deletion R/doJobCollection.R
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ doJobCollection.JobCollection = function(jc, output = NULL) {

# set work dir
if (!fs::dir_exists(jc$work.dir))
return(error("Work dir does not exist"))
return(error("Work dir does not exist: '%s' (node: '%s')", jc$work.dir, Sys.info()[["nodename"]]))
local_dir(jc$work.dir)

# load registry dependencies: packages, source files, ...
Expand Down
9 changes: 7 additions & 2 deletions man/showLog.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions tests/testthat/test_doJobCollection.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,18 @@ test_that("doJobCollection signals slave errors", {
expect_string(getErrorMessages(reg = reg)$message, fixed = "y_on_master")
fs::file_delete(fn)
})

test_that("doJobCollection reports missing work dir with path and node", {
reg = makeTestRegistry()
batchMap(identity, 1, reg = reg)
jc = makeJobCollection(1, reg = reg)
jc$work.dir = fs::path(fs::file_temp(), "nonexistent")
fn = fs::file_temp()
doJobCollection(jc, output = fn)
syncRegistry(reg = reg)
msg = getErrorMessages(reg = reg)$message
expect_string(msg, pattern = "^Work dir does not exist")
expect_string(msg, fixed = jc$work.dir)
expect_string(msg, fixed = Sys.info()[["nodename"]])
fs::file_delete(fn)
})
14 changes: 14 additions & 0 deletions tests/testthat/test_showLog.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,17 @@ test_that("empty log files", {

expect_equal(getLog(1, reg = reg), character(0L))
})

test_that("getLog with missing log files", {
reg = makeTestRegistry()
batchMap(identity, 1, reg = reg)
expect_error(getLog(1, reg = reg), "not available")
expect_identical(getLog(1, missing.as.empty = TRUE, reg = reg), character(0L))

submitAndWait(reg)
fs::file_delete(getLogFiles(reg, 1))
expect_error(getLog(1, reg = reg), "not available")
expect_identical(getLog(1, missing.as.empty = TRUE, reg = reg), character(0L))

expect_error(getLog(1, missing.as.empty = NA, reg = reg), "missing.as.empty")
})
Loading