Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
wlandau committed Jan 31, 2025
2 parents ab8aeaa + e28d0c7 commit fa22fdf
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
9 changes: 7 additions & 2 deletions R/crew_controller.R
Original file line number Diff line number Diff line change
Expand Up @@ -611,10 +611,15 @@ crew_class_controller <- R6::R6Class(
} else {
.timeout <- seconds_timeout * 1000
}
tasks <- .subset2(private, ".tasks")
if (is.null(name)) {
name <- basename(tempfile(pattern = "unnamed_task_"))
name <- name_task_tempfile()
name <- if_any(
is.null(.subset2(tasks, name)),
name,
name_task_nanonext()
)
}
tasks <- .subset2(private, ".tasks")
if (!is.null(.subset2(tasks, name))) {
crew_error(
message = paste(
Expand Down
8 changes: 8 additions & 0 deletions R/utils_names.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@ name_worker <- function(launcher, worker) {
paste("crew", launcher, worker, sep = "-")
}

name_task_tempfile <- function() {
basename(tempfile(pattern = "unnamed_task_"))
}

name_task_nanonext <- function() {
paste0("unnamed_task_", nanonext::random(n = 32L))
}

is_named <- function(x) {
if (!is.list(x) || length(x) < 1L) {
return(TRUE)
Expand Down
8 changes: 8 additions & 0 deletions tests/testthat/test-utils_names.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,11 @@ crew_test("eval_tidyselect()", {
out <- eval_tidyselect(expr = rlang::new_quosure(NULL), choices = "x")
expect_equal(out, character(0L))
})

crew_test("name_task_tempfile()", {
expect_true(is.character(name_task_tempfile()))
})

crew_test("name_task_nanonext()", {
expect_true(is.character(name_task_nanonext()))
})

0 comments on commit fa22fdf

Please sign in to comment.