Skip to content

Commit

Permalink
lints
Browse files Browse the repository at this point in the history
  • Loading branch information
wlandau committed Jan 27, 2025
1 parent 7f43789 commit e5a41f7
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 2 deletions.
1 change: 1 addition & 0 deletions .lintr
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
linters: linters_with_defaults(
cyclocomp_linter = NULL,
infix_spaces_linter = NULL,
object_length_linter = NULL,
object_name_linter = NULL,
Expand Down
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Description: Pipeline tools coordinate the pieces of computationally
The methodology in this package
borrows from GNU 'Make' (2015, ISBN:978-9881443519)
and 'drake' (2018, <doi:10.21105/joss.00550>).
Version: 1.10.0.9001
Version: 1.10.0.9002
License: MIT + file LICENSE
URL: https://docs.ropensci.org/targets/, https://github.com/ropensci/targets
BugReports: https://github.com/ropensci/targets/issues
Expand Down
3 changes: 2 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# targets 1.10.0.9001 (development)
# targets 1.10.0.9002 (development)

* Restore explicit references to "self" in `R6` classes.
* Perform `crew` task retries.

# targets 1.10.0

Expand Down
9 changes: 9 additions & 0 deletions R/class_crew.R
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,15 @@ crew_class <- R6::R6Class(
if (is.null(result)) {
return()
}
if (result$status == "crash") {
target <- pipeline_get_target(self$pipeline, result$name)
self$scheduler$reporter$report_retry(
target = target,
progress = self$scheduler$progress
)
self$run_target(target)
return()
}
tar_assert_all_na(
result$error,
msg = paste("target", result$name, "error:", result$error)
Expand Down
2 changes: 2 additions & 0 deletions R/class_reporter.R
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ reporter_class <- R6::R6Class(
},
report_workspace = function(target) {
},
report_retry = function(target = NULL, progress = NULL) {
},
report_finalize = function(progress = NULL) {
},
flush_messages = function() {
Expand Down
3 changes: 3 additions & 0 deletions R/class_summary.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ summary_class <- R6::R6Class(
report_canceled = function(target = NULL, progress) {
self$report_progress(progress)
},
report_retry = function(target = NULL, progress) {
self$report_progress(progress)
},
report_finalize = function(progress) {
self$report_progress(progress)
self$flush_messages()
Expand Down
10 changes: 10 additions & 0 deletions R/class_timestamp.R
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,16 @@ timestamp_class <- R6::R6Class(
)
)
},
report_retry = function(target, progress = NULL) {
self$buffer_message(
cli_retry(
target_get_name(target),
target_get_type_cli(target),
time_stamp = TRUE,
print = FALSE
)
)
},
report_end = function(progress = NULL, seconds_elapsed = NULL) {
self$flush_messages()
progress$cli_end(time_stamp = TRUE, seconds_elapsed = seconds_elapsed)
Expand Down
9 changes: 9 additions & 0 deletions R/class_verbose.R
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,15 @@ verbose_class <- R6::R6Class(
report_workspace = function(target) {
self$buffer_message(cli_workspace(target_get_name(target), print = FALSE))
},
report_retry = function(target, progress = NULL) {
self$buffer_message(
cli_retry(
target_get_name(target),
target_get_type_cli(target),
print = FALSE
)
)
},
report_finalize = function(progress = NULL) {
self$flush_messages()
},
Expand Down
13 changes: 13 additions & 0 deletions R/utils_cli.R
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,12 @@ cli_workspace <- function(name, time_stamp = FALSE, print = TRUE) {
cli_blue_play(msg, print = print)
}

cli_retry <- function(name, prefix = NULL, time_stamp = FALSE, print = TRUE) {
time <- if_any(time_stamp, time_stamp_cli(), NULL)
msg <- paste(c(time, "retrying", prefix, name), collapse = " ")
cli_magenta_play(msg, print = print)
}

cli_blue_bullet <- function(msg, print = TRUE) {
symbol <- cli_symbol_bullet_blue
msg <- paste(symbol, msg)
Expand All @@ -138,6 +144,12 @@ cli_blue_play <- function(msg, print = TRUE) {
if_any(print, message(msg), msg)
}

cli_magenta_play <- function(msg, print = TRUE) {
symbol <- cli_symbol_play_magenta
msg <- paste(symbol, msg)
if_any(print, message(msg), msg)
}

cli_green_record <- function(msg, print = TRUE) {
symbol <- cli_symbol_record_green
msg <- paste(symbol, msg)
Expand Down Expand Up @@ -241,6 +253,7 @@ cli_url <- function(url) {

cli_symbol_bullet_blue <- cli::col_blue(cli::symbol$bullet)
cli_symbol_play_blue <- cli::col_blue(cli::symbol$play)
cli_symbol_play_magenta <- cli::col_magenta(cli::symbol$play)
cli_symbol_record_green <- cli::col_green(cli::symbol$record)
cli_symbol_box_yellow <- cli::col_yellow(cli::symbol$stop)
cli_symbol_info_cyan <- cli::col_cyan(cli::symbol$info)
Expand Down
33 changes: 33 additions & 0 deletions tests/interactive/test-crew_retries.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
test_that("crew retries", {
tar_script({
tar_option_set(controller = crew::crew_controller_local())
tar_target(x, {
Sys.sleep(15)
"completed despite retries"
})
})
# Run each of the following interactively.
# Terminate the crew worker (open htop, search "crew::crew_worker")
# and observe the retries.
tar_destroy()
tar_make(reporter = "silent")
expect_equal(tar_read(x), "completed despite retries")
tar_destroy()
tar_make(reporter = "verbose")
expect_equal(tar_read(x), "completed despite retries")
tar_destroy()
tar_make(reporter = "verbose_positives")
expect_equal(tar_read(x), "completed despite retries")
tar_destroy()
tar_make(reporter = "timestamp")
expect_equal(tar_read(x), "completed despite retries")
tar_destroy()
tar_make(reporter = "timestamp_positives")
expect_equal(tar_read(x), "completed despite retries")
tar_destroy()
tar_make(reporter = "summary")
expect_equal(tar_read(x), "completed despite retries")
tar_destroy()
tar_make(reporter = "verbose") # Max out the retry quota on this last one.
tar_destroy()
})

0 comments on commit e5a41f7

Please sign in to comment.