Skip to content

Commit

Permalink
Fix #170
Browse files Browse the repository at this point in the history
  • Loading branch information
wlandau committed Jun 7, 2024
1 parent 35e3e44 commit 31b2886
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 7 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Description: In computationally demanding analysis projects,
'clustermq' by Schubert (2019) <doi:10.1093/bioinformatics/btz284>),
and 'batchtools' by Lang, Bischel, and Surmann (2017)
<doi:10.21105/joss.00135>.
Version: 0.9.3.9001
Version: 0.9.3.9002
License: MIT + file LICENSE
URL: https://wlandau.github.io/crew/, https://github.com/wlandau/crew
BugReports: https://github.com/wlandau/crew/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 @@
# crew 0.9.3.9001 (development)
# crew 0.9.3.9002 (development)

* Do not use extended tasks in Shiny vignette.
* Add a new `retry_tasks` argument with default `TRUE` (#170).

# crew 0.9.3

Expand Down
24 changes: 23 additions & 1 deletion R/crew_client.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@
#' @param seconds_timeout Number of seconds until timing
#' out while waiting for certain synchronous operations to complete,
#' such as checking `mirai::status()`.
#' @param retry_tasks `TRUE` to automatically retry a task in the event of
#' an unexpected worker exit. `FALSE` to give up on the first exit and
#' return a `mirai` error code (code number 19).
#' `TRUE` (default) is recommended in most situations.
#' Use `FALSE` for debugging purposes, e.g. to confirm that a task
#' is causing a worker to run out of memory or crash in some other way.
#' @examples
#' if (identical(Sys.getenv("CREW_EXAMPLES"), "true")) {
#' client <- crew_client()
Expand All @@ -37,7 +43,8 @@ crew_client <- function(
tls_enable = NULL,
tls_config = NULL,
seconds_interval = 0.5,
seconds_timeout = 5
seconds_timeout = 5,
retry_tasks = TRUE
) {
crew_deprecate(
name = "tls_enable",
Expand Down Expand Up @@ -69,6 +76,7 @@ crew_client <- function(
tls = tls,
seconds_interval = seconds_interval,
seconds_timeout = seconds_timeout,
retry_tasks = retry_tasks,
relay = crew_relay()
)
client$validate()
Expand Down Expand Up @@ -98,6 +106,7 @@ crew_class_client <- R6::R6Class(
.tls = NULL,
.seconds_interval = NULL,
.seconds_timeout = NULL,
.retry_tasks = NULL,
.relay = NULL,
.started = NULL,
.dispatcher = NULL
Expand Down Expand Up @@ -131,6 +140,10 @@ crew_class_client <- R6::R6Class(
seconds_timeout = function() {
.subset2(private, ".seconds_timeout")
},
#' @field retry_tasks See [crew_client()]
retry_tasks = function() {
.subset2(private, ".retry_tasks")
},
#' @field relay Relay object for event-driven programming on a downstream
#' condition variable.
relay = function() {
Expand All @@ -155,6 +168,7 @@ crew_class_client <- R6::R6Class(
#' @param tls Argument passed from [crew_client()].
#' @param seconds_interval Argument passed from [crew_client()].
#' @param seconds_timeout Argument passed from [crew_client()].
#' @param retry_tasks Argument passed from [crew_client()].
#' @param relay Argument passed from [crew_client()].
#' @examples
#' if (identical(Sys.getenv("CREW_EXAMPLES"), "true")) {
Expand All @@ -171,6 +185,7 @@ crew_class_client <- R6::R6Class(
tls = NULL,
seconds_interval = NULL,
seconds_timeout = NULL,
retry_tasks = NULL,
relay = NULL
) {
private$.name <- name
Expand All @@ -180,6 +195,7 @@ crew_class_client <- R6::R6Class(
private$.tls <- tls
private$.seconds_interval <- seconds_interval
private$.seconds_timeout <- seconds_timeout
private$.retry_tasks <- retry_tasks
private$.relay <- relay
},
#' @description Validate the client.
Expand Down Expand Up @@ -224,6 +240,11 @@ crew_class_client <- R6::R6Class(
. >= 0
)
}
crew_assert(
private$.retry_tasks,
isTRUE(.) || isFALSE(.),
message = "retry_tasks must be TRUE or FALSE"
)
crew_assert(
private$.dispatcher %|||% 0L,
is.numeric(.),
Expand Down Expand Up @@ -256,6 +277,7 @@ crew_class_client <- R6::R6Class(
tls = private$.tls$client(),
pass = private$.tls$password,
token = TRUE,
retry = private$.retry_tasks,
.compute = private$.name
)
# TODO: remove code that gets the dispatcher PID if the dispatcher
Expand Down
4 changes: 3 additions & 1 deletion R/crew_controller_local.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ crew_controller_local <- function(
seconds_idle = Inf,
seconds_wall = Inf,
seconds_exit = NULL,
retry_tasks = TRUE,
tasks_max = Inf,
tasks_timers = 0L,
reset_globals = TRUE,
Expand Down Expand Up @@ -56,7 +57,8 @@ crew_controller_local <- function(
tls_enable = tls_enable,
tls_config = tls_config,
seconds_interval = seconds_interval,
seconds_timeout = seconds_timeout
seconds_timeout = seconds_timeout,
retry_tasks = retry_tasks
)
launcher <- crew_launcher_local(
name = name,
Expand Down
5 changes: 5 additions & 0 deletions man/crew_class_client.Rd

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

10 changes: 9 additions & 1 deletion man/crew_client.Rd

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

8 changes: 8 additions & 0 deletions man/crew_controller_local.Rd

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

4 changes: 3 additions & 1 deletion tests/local/test-launcher-system2.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ crew_test("custom launcher plugin based on system2()", {
seconds_launch = 30,
seconds_idle = Inf,
seconds_wall = Inf,
retry_tasks = TRUE,
tasks_max = Inf,
tasks_timers = 0L,
reset_globals = TRUE,
Expand All @@ -41,7 +42,8 @@ crew_test("custom launcher plugin based on system2()", {
port = port,
tls = tls,
seconds_interval = seconds_interval,
seconds_timeout = seconds_timeout
seconds_timeout = seconds_timeout,
retry_tasks = retry_tasks
)
launcher <- system2_launcher_class$new(
name = name,
Expand Down
4 changes: 3 additions & 1 deletion tests/testthat/test-crew_client.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ crew_test("crew_client() active bindings", {
host = "127.0.0.1",
port = 123L,
seconds_interval = 123,
seconds_timeout = 456
seconds_timeout = 456,
retry_tasks = FALSE
)
expect_equal(client$host, "127.0.0.1")
expect_equal(client$port, 123L)
expect_equal(client$seconds_interval, 123)
expect_equal(client$seconds_timeout, 456)
expect_false(client$retry_tasks)
expect_true(inherits(client$tls, "crew_class_tls"))
expect_silent(client$validate())
})
Expand Down

0 comments on commit 31b2886

Please sign in to comment.