-
Notifications
You must be signed in to change notification settings - Fork 129
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 #544 from ropensci/539
Optionally load targets in parallel workers
- Loading branch information
Showing
12 changed files
with
208 additions
and
128 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 |
---|---|---|
@@ -0,0 +1,106 @@ | ||
mc_get_checksum <- function(target, config){ | ||
paste( | ||
safe_get_hash( | ||
key = target, | ||
namespace = config$cache$default_namespace, | ||
config = config | ||
), | ||
safe_get_hash(key = target, namespace = "kernels", config = config), | ||
safe_get_hash(key = target, namespace = "meta", config = config), | ||
safe_get_hash(key = target, namespace = "attempt", config = config), | ||
mc_get_outfile_checksum(target, config), | ||
sep = " " | ||
) | ||
} | ||
|
||
mc_get_outfile_checksum <- function(target, config){ | ||
deps <- vertex_attr( | ||
graph = config$graph, | ||
name = "deps", | ||
index = target | ||
)[[1]] | ||
files <- sort(unique(as.character(deps$file_out))) | ||
vapply( | ||
X = files, | ||
FUN = rehash_file, | ||
FUN.VALUE = character(1), | ||
config = config | ||
) %>% | ||
paste(collapse = "") %>% | ||
digest::digest(algo = config$long_hash_algo, serialize = FALSE) | ||
} | ||
|
||
mc_is_good_checksum <- function(target, checksum, config){ | ||
# Not actually reached, but may come in handy later. | ||
# nocov start | ||
if (!length(checksum)){ | ||
mc_warn_no_checksum(target = target, config = config) | ||
return(TRUE) | ||
} | ||
if (identical("failed", get_progress_single(target, cache = config$cache))){ | ||
return(TRUE) # covered with parallel processes # nocov | ||
} | ||
# nocov end | ||
local_checksum <- mc_get_checksum(target = target, config = config) | ||
if (!identical(local_checksum, checksum)){ | ||
return(FALSE) | ||
} | ||
all( | ||
vapply( | ||
X = unlist(strsplit(local_checksum, " "))[1:3], # Exclude attempt flag (often NA). # nolint | ||
config$cache$exists_object, | ||
FUN.VALUE = logical(1) | ||
) | ||
) | ||
} | ||
|
||
mc_is_good_outfile_checksum <- function(target, checksum, config){ | ||
if (!length(checksum)){ | ||
mc_warn_no_checksum(target = target, config = config) | ||
return(TRUE) | ||
} | ||
if (identical("failed", get_progress_single(target, cache = config$cache))){ | ||
return(TRUE) # covered with parallel processes # nocov | ||
} | ||
identical(checksum, mc_get_outfile_checksum(target = target, config = config)) | ||
} | ||
|
||
mc_wait_checksum <- function( | ||
target, | ||
checksum, | ||
config, | ||
timeout = 300, | ||
criterion = mc_is_good_checksum | ||
){ | ||
i <- 0 | ||
while (i < timeout / mc_wait){ | ||
if (criterion(target, checksum, config)){ | ||
return() | ||
} else { | ||
Sys.sleep(mc_wait) | ||
} | ||
i <- i + 1 | ||
} | ||
drake_error( | ||
"Target `", target, "` did not download from your ", | ||
"network file system. Checksum verification timed out after about ", | ||
timeout, " seconds.", config = config | ||
) | ||
} | ||
|
||
mc_wait_outfile_checksum <- function(target, checksum, config, timeout = 300){ | ||
mc_wait_checksum( | ||
target = target, | ||
checksum = checksum, | ||
config = config, | ||
timeout = timeout, | ||
criterion = mc_is_good_outfile_checksum | ||
) | ||
} | ||
|
||
mc_warn_no_checksum <- function(target, config){ | ||
drake_warning( | ||
"No checksum available for target ", target, ".", | ||
config = config | ||
) | ||
} |
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.