Skip to content

Commit

Permalink
collect arg of pop()
Browse files Browse the repository at this point in the history
  • Loading branch information
wlandau-lilly committed May 22, 2023
1 parent ff0d09c commit 388846b
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 10 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* Throttle auto-scaling with interval `self$router$seconds_interval` (#76).
* Remove `clean()` and instead terminate lost workers on launch.
* Fix examples.
* Add a `collect` argument to `pop()`.

# crew 0.1.1

Expand Down
22 changes: 16 additions & 6 deletions R/crew_controller.R
Original file line number Diff line number Diff line change
Expand Up @@ -401,14 +401,19 @@ crew_class_controller <- R6::R6Class(
#' value is a one-row data frame with the results, warnings, and errors.
#' Otherwise, if there are no results available to collect,
#' the return value is `NULL`.
#' @param scale Logical, whether to automatically call `scale_later()`
#' @param scale Logical of length 1,
#' whether to automatically call `scale()`
#' to auto-scale workers to meet the demand of the task load.
#' Auto-scaling might not actually happen if `throttle` is `TRUE`.
#' If `TRUE`, then `collect()` runs first
#' so demand can be properly assessed before scaling and the number
#' of workers is not too high. Scaling up on `pop()` may be important
#' for transient or nearly transient workers that tend to drop off
#' quickly after doing little work.
#' @param collect Logical of length 1. If `scale` is `FALSE`,
#' whether to call `collect()`
#' to pick up the results of completed tasks. This task collection
#' step always happens (with throttling) when `scale` is `TRUE`.
#' @param throttle Whether to defer auto-scaling and task collection
#' until the next request at least
#' `self$router$seconds_interval` seconds from the original request.
Expand All @@ -417,12 +422,17 @@ crew_class_controller <- R6::R6Class(
#' and efficiency.
#' @param controllers Not used. Included to ensure the signature is
#' compatible with the analogous method of controller groups.
pop = function(scale = TRUE, throttle = TRUE, controllers = NULL) {
if_any(
scale,
self$scale(throttle = throttle),
pop = function(
scale = TRUE,
collect = TRUE,
throttle = TRUE,
controllers = NULL
) {
if (scale) {
self$scale(throttle = throttle)
} else if (collect) {
self$collect(throttle = throttle)
)
}
out <- NULL
if (length(self$results) > 0L) {
task <- self$results[[1L]]
Expand Down
17 changes: 15 additions & 2 deletions R/crew_controller_group.R
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,10 @@ crew_class_controller_group <- R6::R6Class(
#' of workers is not too high. Scaling up on `pop()` may be important
#' for transient or nearly transient workers that tend to drop off
#' quickly after doing little work.
#' @param collect Logical of length 1. If `scale` is `FALSE`,
#' whether to call `collect()`
#' to pick up the results of completed tasks. This task collection
#' step always happens (with throttling) when `scale` is `TRUE`.
#' @param throttle If `scale` is `TRUE`, whether to defer auto-scaling
#' until the next auto-scaling request at least
#' `self$router$seconds_interval` seconds from the original request.
Expand All @@ -302,10 +306,19 @@ crew_class_controller_group <- R6::R6Class(
#' and efficiency.
#' @param controllers Character vector of controller names.
#' Set to `NULL` to select all controllers.
pop = function(scale = TRUE, throttle = TRUE, controllers = NULL) {
pop = function(
scale = TRUE,
collect = TRUE,
throttle = TRUE,
controllers = NULL
) {
control <- private$select_controllers(controllers)
for (controller in control) {
out <- controller$pop(scale = scale, throttle = throttle)
out <- controller$pop(
scale = scale,
collect = collect,
throttle = throttle
)
if (!is.null(out)) {
return(out)
}
Expand Down
15 changes: 13 additions & 2 deletions man/crew_class_controller.Rd

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

6 changes: 6 additions & 0 deletions man/crew_class_controller_group.Rd

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

0 comments on commit 388846b

Please sign in to comment.