Skip to content

Commit

Permalink
write #1331
Browse files Browse the repository at this point in the history
  • Loading branch information
wlandau committed Sep 9, 2024
1 parent 4ef51fa commit 1ec5ac5
Show file tree
Hide file tree
Showing 10 changed files with 89 additions and 30 deletions.
4 changes: 3 additions & 1 deletion R/class_active.R
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,9 @@ active_class <- R6::R6Class(
target <- pipeline_get_target(self$pipeline, name)
target_debug(target)
target_update_depend(target, self$pipeline, self$meta)
if (target_should_run(target, self$meta)) {
if (counter_exists_name(self$scheduler$trimmed, name)) {
self$scheduler$trim(target, self$pipeline)
} else if (target_should_run(target, self$meta)) {
self$flush_upload_meta_file(target)
self$run_target(name)
} else {
Expand Down
2 changes: 1 addition & 1 deletion R/class_builder.R
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ builder_handle_error <- function(target, pipeline, scheduler, meta) {
target$settings$error,
continue = builder_error_continue(target, scheduler),
abridge = scheduler$abridge(target),
trim = scheduler$trim(target),
trim = scheduler$trim(target, pipeline),
stop = builder_error_exit(target, pipeline, scheduler, meta),
null = builder_error_null(target, pipeline, scheduler, meta),
workspace = builder_error_exit(target, pipeline, scheduler, meta)
Expand Down
2 changes: 1 addition & 1 deletion R/class_pattern.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pattern_new <- function(

#' @export
target_get_children.tar_pattern <- function(target) {
target$junction$splits
as.character(target$junction$splits)
}

#' @export
Expand Down
26 changes: 14 additions & 12 deletions R/class_scheduler.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ scheduler_init <- function(
)
reporter <- reporter_init(reporter, seconds_interval = seconds_reporter)
backoff <- tar_options$get_backoff()
canceled <- counter_init()
trimmed <- counter_init()
scheduler_new(
graph = graph,
queue = queue,
progress = progress,
reporter = reporter,
backoff = backoff,
canceled <- canceled
trimmed <- trimmed
)
}

Expand All @@ -55,9 +55,9 @@ scheduler_new <- function(
progress = NULL,
reporter = NULL,
backoff = NULL,
canceled = NULL
trimmed = NULL
) {
scheduler_class$new(graph, queue, progress, reporter, backoff, canceled)
scheduler_class$new(graph, queue, progress, reporter, backoff, trimmed)
}

scheduler_class <- R6::R6Class(
Expand All @@ -71,21 +71,21 @@ scheduler_class <- R6::R6Class(
progress = NULL,
reporter = NULL,
backoff = NULL,
canceled = NULL,
trimmed = NULL,
initialize = function(
graph = NULL,
queue = NULL,
progress = NULL,
reporter = NULL,
backoff = NULL,
canceled = NULL
trimmed = NULL
) {
self$graph <- graph
self$queue <- queue
self$progress <- progress
self$reporter <- reporter
self$backoff <- backoff
self$canceled <- canceled
self$trimmed <- trimmed
},
count_unfinished_deps = function(name) {
deps <- self$graph$produce_upstream(name)
Expand All @@ -104,18 +104,20 @@ scheduler_class <- R6::R6Class(
self$progress$abridge()
self$queue$abridge()
},
trim = function(target) {

browser()

trim = function(target, pipeline) {
parent_name <- target_get_parent(target)
parent_target <- pipeline_get_target(pipeline, parent_name)
downstream <- self$graph$produce_downstream(parent_name)
siblings <- target_get_children(parent_target)
counter_set_names(self$trimmed, c(downstream, siblings))
},
validate = function() {
self$graph$validate()
self$queue$validate()
self$progress$validate()
self$reporter$validate()
self$backoff$validate()
counter_validate(self$canceled)
counter_validate(self$trimmed)
}
)
)
8 changes: 7 additions & 1 deletion R/class_stem.R
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,13 @@ target_produce_record.tar_stem <- function(target, pipeline, meta) {
}

#' @export
target_skip.tar_stem <- function(target, pipeline, scheduler, meta, active) {
target_skip.tar_stem <- function(
target,
pipeline,
scheduler,
meta,
active
) {
NextMethod()
stem_restore_buds(target, pipeline, scheduler, meta)
}
Expand Down
8 changes: 7 additions & 1 deletion R/class_target.R
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,13 @@ target_produce_record <- function(target, pipeline, meta) {
UseMethod("target_produce_record")
}

target_skip <- function(target, pipeline, scheduler, meta, active) {
target_skip <- function(
target,
pipeline,
scheduler,
meta,
active
) {
UseMethod("target_skip")
}

Expand Down
15 changes: 11 additions & 4 deletions R/tar_target.R
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,17 @@
#' up to date for the next run of the pipeline.
#' * `"abridge"`: any currently running targets keep running,
#' but no new targets launch after that.
#' * `"trim"`: any currently running targets keep running,
#' and everything downstream of the error is canceled.
#' In addition, if the error happens in a dynamic branch,
#' then all not-yet-dispatched sibling branches are canceled.
#' * `"trim"`: all currently running targets stay running. In addition,
#' a target not yet running is allowed to start if:
#'
#' 1. It is not downstream of the error, and
#' 2. It is not a sibling branch from the same [tar_target()] call
#' (if the error happened in a dynamic branch).
#'
#' The idea is to avoid starting any new work that the immediate error
#' impacts. `error = "trim"` is just like `error = "abridge"`,
#' but it allows potentially healthy regions of the dependency graph
#' to begin running.
#' (Visit <https://books.ropensci.org/targets/debugging.html>
#' to learn how to debug targets using saved workspaces.)
#' @param memory Character of length 1, memory strategy.
Expand Down
18 changes: 15 additions & 3 deletions man/tar_option_set.Rd

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

18 changes: 15 additions & 3 deletions man/tar_target.Rd

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

18 changes: 15 additions & 3 deletions man/tar_target_raw.Rd

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

0 comments on commit 1ec5ac5

Please sign in to comment.