Skip to content

Commit

Permalink
clean up logic for existing behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
wlandau committed Nov 10, 2024
1 parent ae94463 commit b864b0c
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 14 deletions.
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,9 @@ S3method(target_validate,tar_builder)
S3method(target_validate,tar_pattern)
S3method(target_validate,tar_stem)
S3method(target_validate,tar_target)
S3method(target_worker_extras,tar_bud)
S3method(target_worker_extras,tar_pattern)
S3method(target_worker_extras,tar_target)
S3method(value_count_slices,tar_group)
S3method(value_count_slices,tar_list)
S3method(value_count_slices,tar_vector)
Expand Down
5 changes: 5 additions & 0 deletions R/class_bud.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ target_produce_reference.tar_bud <- function(target) {
reference_init(parent = target_get_parent(target))
}

#' @export
target_worker_extras.tar_bud <- function(target, pipeline, retrieval_worker) {
if_any(retrieval_worker, target_get_parent(target), character(0L))
}

#' @export
target_validate.tar_bud <- function(target) {
tar_assert_correct_fields(target, bud_new, optional = "value")
Expand Down
9 changes: 9 additions & 0 deletions R/class_pattern.R
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,15 @@ target_produce_child.tar_pattern <- function(target, name) {
pattern_produce_branch(target, name)
}

#' @export
target_worker_extras.tar_pattern <- function(
target,
pipeline,
retrieval_worker
) {
target_get_children(target)
}

#' @export
print.tar_pattern <- function(x, ...) {
cat(
Expand Down
35 changes: 21 additions & 14 deletions R/class_target.R
Original file line number Diff line number Diff line change
Expand Up @@ -154,22 +154,29 @@ target_deps_shallow <- function(target, pipeline) {

target_deps_deep <- function(target, pipeline) {
deps <- target_deps_shallow(target, pipeline)
children <- unlist(
lapply(deps, function(dep) {
target_get_children(pipeline_get_target(pipeline, dep))
})
)
retrieval_worker <- identical(target$settings$retrieval, "worker")
parents <- unlist(
map(deps, function(dep) {
dep <- pipeline_get_target(pipeline, dep)
if (inherits(dep, "tar_bud") && retrieval_worker) {
return(target_get_parent(dep))
}
NULL
})
extras <- map(
deps,
~target_worker_extras(
target = pipeline_get_target(pipeline, .x),
pipeline = pipeline,
retrieval_worker = retrieval_worker
)
)
unique(c(deps, children, parents))
unique(as.character(c(deps, unlist(extras))))
}

target_worker_extras <- function(target, pipeline, retrieval_worker) {
UseMethod("target_worker_extras")
}

#' @export
target_worker_extras.tar_target <- function(
target,
pipeline,
retrieval_worker
) {
character(0L)
}

target_downstream_branching <- function(target, pipeline, scheduler) {
Expand Down

0 comments on commit b864b0c

Please sign in to comment.