Skip to content

Commit

Permalink
only flush skipped reporter messages
Browse files Browse the repository at this point in the history
  • Loading branch information
wlandau-lilly committed Nov 14, 2023
1 parent 7115068 commit d9c8f0f
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 1 deletion.
1 change: 1 addition & 0 deletions R/class_forecast.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ forecast_class <- R6::R6Class(
}
},
report_outdated = function(outdated) {
super$report_outdated(outdated)
self$buffer <- cli_forecast(outdated$cli_data(), print = FALSE)
self$poll()
},
Expand Down
12 changes: 11 additions & 1 deletion R/class_reporter.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,17 @@ reporter_class <- R6::R6Class(
seconds_interval = NULL,
buffer = NULL,
seconds_flushed = NULL,
next_flush = NULL,
initialize = function(seconds_interval = NULL) {
self$seconds_interval <- seconds_interval
},
poll = function() {
self$seconds_flushed <- self$seconds_flushed %|||% -Inf
now <- time_seconds_local()
if ((now - self$seconds_flushed) > self$seconds_interval) {
enough_elapsed <- (now - self$seconds_flushed) > self$seconds_interval
can_flush <- !is.null(self$next_flush) && self$next_flush
if (enough_elapsed && can_flush) {
self$next_flush <- FALSE
self$flush_messages()
self$seconds_flushed <- time_seconds_local()
}
Expand All @@ -54,18 +58,24 @@ reporter_class <- R6::R6Class(
}
},
report_started = function(target = NULL, progress = NULL) {
self$next_flush <- TRUE
},
report_built = function(target = NULL, progress = NULL) {
self$next_flush <- TRUE
},
report_skipped = function(target = NULL, progress = NULL) {
},
report_errored = function(target = NULL, progress = NULL) {
self$next_flush <- TRUE
},
report_canceled = function(target = NULL, progress = NULL) {
self$next_flush <- TRUE
},
report_outdated = function(outdated) {
self$next_flush <- TRUE
},
report_workspace = function(target) {
self$next_flush <- TRUE
},
validate = function() {
}
Expand Down
6 changes: 6 additions & 0 deletions R/class_summary.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,30 @@ summary_class <- R6::R6Class(
report_error = function(error) {
},
report_started = function(target = NULL, progress) {
super$report_started(target = target, progress = progress)
self$report_progress(progress)
},
report_built = function(target = NULL, progress) {
super$report_built(target = target, progress = progress)
self$report_progress(progress)
},
report_skipped = function(target = NULL, progress) {
super$report_skipped(target = target, progress = progress)
self$report_progress(progress)
},
report_errored = function(target = NULL, progress) {
super$report_errored(target = target, progress = progress)
self$report_progress(progress)
},
report_canceled = function(target = NULL, progress) {
super$report_canceled(target = target, progress = progress)
self$report_progress(progress)
},
report_end = function(progress, seconds_elapsed = NULL) {
self$report_progress(progress)
self$flush_messages()
message("")
super$report_end(progress)
}
)
)
6 changes: 6 additions & 0 deletions R/class_timestamp.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ timestamp_class <- R6::R6Class(
self$poll()
},
report_started = function(target, progress = NULL) {
super$report_started(target = target, progress = progress)
self$buffer_message(
cli_start(
target_get_name(target),
Expand All @@ -30,6 +31,7 @@ timestamp_class <- R6::R6Class(
)
},
report_built = function(target, progress) {
super$report_built(target = target, progress = progress)
self$buffer_message(
cli_built(
target_get_name(target),
Expand All @@ -41,6 +43,7 @@ timestamp_class <- R6::R6Class(
)
},
report_skipped = function(target, progress) {
super$report_skipped(target = target, progress = progress)
self$buffer_message(
cli_skip(
target_get_name(target),
Expand All @@ -51,6 +54,7 @@ timestamp_class <- R6::R6Class(
)
},
report_errored = function(target, progress = NULL) {
super$report_errored(target = target, progress = progress)
self$buffer_message(
cli_error(
target_get_name(target),
Expand All @@ -61,6 +65,7 @@ timestamp_class <- R6::R6Class(
)
},
report_canceled = function(target = NULL, progress = NULL) {
super$report_canceled(target = target, progress = progress)
self$buffer_message(
cli_cancel(
target_get_name(target),
Expand All @@ -71,6 +76,7 @@ timestamp_class <- R6::R6Class(
)
},
report_workspace = function(target) {
super$report_workspace(target = target)
self$buffer_message(
cli_workspace(
target_get_name(target),
Expand Down
6 changes: 6 additions & 0 deletions R/class_verbose.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ verbose_class <- R6::R6Class(
self$poll()
},
report_started = function(target, progress = NULL) {
super$report_started(target = target, progress = progress)
self$buffer_message(
cli_start(
target_get_name(target),
Expand All @@ -29,6 +30,7 @@ verbose_class <- R6::R6Class(
)
},
report_built = function(target, progress = NULL) {
super$report_built(target = target, progress = progress)
self$buffer_message(
cli_built(
name = target_get_name(target),
Expand All @@ -39,6 +41,7 @@ verbose_class <- R6::R6Class(
)
},
report_skipped = function(target, progress = NULL) {
super$report_skipped(target = target, progress = progress)
self$buffer_message(
cli_skip(
target_get_name(target),
Expand All @@ -48,6 +51,7 @@ verbose_class <- R6::R6Class(
)
},
report_errored = function(target, progress = NULL) {
super$report_errored(target = target, progress = progress)
self$buffer_message(
cli_error(
target_get_name(target),
Expand All @@ -57,6 +61,7 @@ verbose_class <- R6::R6Class(
)
},
report_canceled = function(target = NULL, progress = NULL) {
super$report_canceled(target = target, progress = progress)
self$buffer_message(
cli_cancel(
target_get_name(target),
Expand All @@ -66,6 +71,7 @@ verbose_class <- R6::R6Class(
)
},
report_workspace = function(target) {
super$report_workspace(target = target)
self$buffer_message(cli_workspace(target_get_name(target), print = FALSE))
},
report_end = function(progress = NULL, seconds_elapsed = NULL) {
Expand Down

0 comments on commit d9c8f0f

Please sign in to comment.