Skip to content

Commit 1797840

Browse files
Add internal batchtools_getLog()
1 parent 6ece47d commit 1797840

File tree

2 files changed

+28
-25
lines changed

2 files changed

+28
-25
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Package: future.batchtools
2-
Version: 0.12.2-9929
2+
Version: 0.12.2-9930
33
Depends:
44
R (>= 3.2.0),
55
parallelly,

R/BatchtoolsFutureBackend-class.R

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,28 @@ loggedError.BatchtoolsFuture <- function(future, ...) {
585585
} # loggedError()
586586

587587

588+
batchtools_getLog <- function(id, reg, timeout = NULL) {
589+
debug <- isTRUE(getOption("future.debug"))
590+
if (debug) {
591+
mdebug_push("batchtools::getLog() ...")
592+
on.exit(mdebug_pop())
593+
}
594+
595+
if (!is.null(timeout)) {
596+
stopifnot(length(timeout) == 1, is.numeric(timeout), !is.na(timeout), timeout >= 0.0)
597+
oldValue <- reg$cluster.functions$fs.latency
598+
on.exit({
599+
reg$cluster.functions$fs.latency <- oldValue
600+
}, add = TRUE)
601+
reg$cluster.functions$fs.latency <- timeout
602+
}
603+
604+
tryCatch(suppressWarnings({
605+
getLog(id = id, reg = reg)
606+
}), error = function(e) NULL)
607+
} ## batchtools_getLog()
608+
609+
588610
#' @importFrom batchtools getLog
589611
#' @export
590612
loggedOutput.BatchtoolsFuture <- function(future, timeout = NULL, ...) {
@@ -602,19 +624,7 @@ loggedOutput.BatchtoolsFuture <- function(future, timeout = NULL, ...) {
602624
if (!inherits(reg, "Registry")) return(NULL)
603625
jobid <- config$jobid
604626

605-
out <- local({
606-
if (!is.null(timeout)) {
607-
stopifnot(length(timeout) == 1, is.numeric(timeout), !is.na(timeout), timeout >= 0.0)
608-
oldValue <- reg$cluster.functions$fs.latency
609-
on.exit(reg$cluster.functions$fs.latency <- oldValue)
610-
reg$cluster.functions$fs.latency <- timeout
611-
}
612-
tryCatch(suppressWarnings({
613-
getLog(id = jobid, reg = reg)
614-
}), error = function(e) NULL)
615-
})
616-
617-
out
627+
batchtools_getLog(id = jobid, reg = reg, timeout = timeout)
618628
} # loggedOutput()
619629

620630

@@ -784,17 +794,10 @@ await <- function(future, cleanup = TRUE, ...) {
784794

785795
if (inherits(result, "FutureResult")) {
786796
prototype_fields <- c(prototype_fields, "batchtools_log")
787-
result[["batchtools_log"]] <- try(local({
788-
if (debug) {
789-
mdebug_push("batchtools::getLog() ...")
790-
on.exit(mdebug_pop())
791-
}
792-
## Since we're already collected the results, the log file
793-
## should already exist, if it exists. Because of this,
794-
## only poll for the log file for a second before giving up.
795-
reg$cluster.functions$fs.latency <- 1.0
796-
getLog(id = jobid, reg = reg)
797-
}), silent = TRUE)
797+
## Since we're already collected the results, the log file
798+
## should already exist, if it exists. Because of this,
799+
## only poll for the log file for a second before giving up.
800+
result[["batchtools_log"]] <- batchtools_getLog(id = jobid, reg = reg, timeout = 1.0)
798801
if (result_has_errors(result)) cleanup <- FALSE
799802
}
800803
} else if ("error" %in% stat) {

0 commit comments

Comments
 (0)