Skip to content

Commit

Permalink
tar_unblock_process()
Browse files Browse the repository at this point in the history
  • Loading branch information
wlandau-lilly committed Nov 14, 2024
1 parent 085639e commit 90ebe9a
Show file tree
Hide file tree
Showing 24 changed files with 118 additions and 19 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,7 @@ export(tar_timestamp)
export(tar_timestamp_raw)
export(tar_toggle)
export(tar_traceback)
export(tar_unblock_process)
export(tar_unscript)
export(tar_unversion)
export(tar_validate)
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
* Compress branches into references when `retrieval` is `"worker"` and the whole pattern is part of the subpipeline.
* Avoid duplicated branch aggregation: just send the branches over the network.
* Back-compatibly switch `format = "qs"` from `qs` to `qs2` (#1373).
* Add `tar_unblock_process()`.

# targets 1.8.0

Expand Down
10 changes: 8 additions & 2 deletions R/class_process.R
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,15 @@ process_class <- R6::R6Class(
pid,
"is really a {targets} pipeline and not a false positive,",
"then terminate it manually. In case of a false positive,",
"remove the file",
"run",
sprintf(
"targets::tar_unblock_process(store = \"%s\")",
dirname(dirname(self$database$path))
),
"(or manually remove",
shQuote(self$database$path),
"and try again. False positives may happen if you run",
") and try again.",
"False positives may happen if you run",
"different calls to tar_make() in quick succession",
"or if you run tar_make(callr_function = NULL) in a",
"different R process and keep that process running."
Expand Down
20 changes: 20 additions & 0 deletions R/tar_unblock_process.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#' @title Unblock the pipeline process
#' @export
#' @family utilities
#' @description `targets` tries to avoid running two concurrent instances
#' of [tar_make()] on the same pipeline writing to the same data store.
#' Sometimes it generates false positives (meaning [tar_make()] throws
#' this error even though there is only one instance of the pipeline
#' running.) If there is a false positive, [tar_unblock_process()]
#' gets the pipeline unstuck by removing the `_targets/meta/process` file.
#' This allows the next call to [tar_make()] to resume.
#' @return `NULL` (invisibly). Called for its side effects.
#' @param store Character string, path to the data store
#' (usually `"_targets"`).
tar_unblock_process <- function(store = targets::tar_config_get("store")) {
tar_assert_allow_meta("tar_meta", store)
tar_assert_scalar(store)
tar_assert_chr(store)
tar_assert_nzchar(store)
unlink(path_process(store), force = TRUE)
}
1 change: 1 addition & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ reference:
- 'tar_path_store'
- 'tar_path_target'
- 'tar_source'
- 'tar_unblock_store'
- title: Extending targets
contents:
- 'tar_assert'
Expand Down
3 changes: 2 additions & 1 deletion man/tar_active.Rd

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

3 changes: 2 additions & 1 deletion man/tar_backoff.Rd

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

3 changes: 2 additions & 1 deletion man/tar_call.Rd

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

3 changes: 2 additions & 1 deletion man/tar_cancel.Rd

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

3 changes: 2 additions & 1 deletion man/tar_definition.Rd

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

3 changes: 2 additions & 1 deletion man/tar_described_as.Rd

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

3 changes: 2 additions & 1 deletion man/tar_envir.Rd

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

3 changes: 2 additions & 1 deletion man/tar_format_get.Rd

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

3 changes: 2 additions & 1 deletion man/tar_group.Rd

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

3 changes: 2 additions & 1 deletion man/tar_name.Rd

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

3 changes: 2 additions & 1 deletion man/tar_path.Rd

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

3 changes: 2 additions & 1 deletion man/tar_path_script.Rd

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

3 changes: 2 additions & 1 deletion man/tar_path_script_support.Rd

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

3 changes: 2 additions & 1 deletion man/tar_path_store.Rd

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

3 changes: 2 additions & 1 deletion man/tar_path_target.Rd

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

3 changes: 2 additions & 1 deletion man/tar_source.Rd

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

3 changes: 2 additions & 1 deletion man/tar_store.Rd

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

45 changes: 45 additions & 0 deletions man/tar_unblock_process.Rd

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

8 changes: 8 additions & 0 deletions tests/testthat/test-tar_unblock_process.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
targets::tar_test("tar_unblock_process()", {
skip_cran()
tar_script(tar_target(x, 1))
tar_make(callr_function = NULL)
expect_true(file.exists(path_process(path_store_default())))
tar_unblock_process()
expect_false(file.exists(path_process(path_store_default())))
})

0 comments on commit 90ebe9a

Please sign in to comment.