From 81e9238a24aa5749e1f6f99c08519bc54d1a6dd2 Mon Sep 17 00:00:00 2001 From: shikokuchuo <53399081+shikokuchuo@users.noreply.github.com> Date: Tue, 3 Dec 2024 22:06:43 +0000 Subject: [PATCH] fold legacy dispatcher into dispatcher --- DESCRIPTION | 2 +- NAMESPACE | 1 - NEWS.md | 2 +- R/daemon.R | 8 ++--- R/daemons.R | 4 +-- R/dispatcher.R | 35 ++++++--------------- man/dispatcher.Rd | 13 +++++++- man/dispatcher_v1.Rd | 73 -------------------------------------------- tests/tests.R | 2 ++ 9 files changed, 32 insertions(+), 108 deletions(-) delete mode 100644 man/dispatcher_v1.Rd diff --git a/DESCRIPTION b/DESCRIPTION index 584d98f9..369c332d 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: mirai Type: Package Title: Minimalist Async Evaluation Framework for R -Version: 1.3.1.9015 +Version: 1.3.1.9016 Description: Designed for simplicity, a 'mirai' evaluates an R expression asynchronously in a parallel process, locally or distributed over the network, with the result automatically available upon completion. Modern diff --git a/NAMESPACE b/NAMESPACE index 5b665f2b..74a2f76c 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -30,7 +30,6 @@ export(collect_mirai) export(daemon) export(daemons) export(dispatcher) -export(dispatcher_v1) export(everywhere) export(host_url) export(is_error_value) diff --git a/NEWS.md b/NEWS.md index a7ff5d38..724ba6bb 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,4 @@ -# mirai 1.3.1.9015 (development) +# mirai 1.3.1.9016 (development) #### Architecture Change diff --git a/R/daemon.R b/R/daemon.R index 31b7c940..5568caa2 100644 --- a/R/daemon.R +++ b/R/daemon.R @@ -106,7 +106,7 @@ daemon <- function(url, ..., dispatcher = FALSE, asyncdial = FALSE, autoexit = T cleanup = TRUE, output = FALSE, tls = NULL, rs = NULL) { dispatcher || return( - ddaemon( + daemon_legacy( url = url, asyncdial = asyncdial, autoexit = autoexit, cleanup = cleanup, output = output, ..., tls = tls, rs = rs ) @@ -146,9 +146,9 @@ daemon <- function(url, ..., dispatcher = FALSE, asyncdial = FALSE, autoexit = T } -ddaemon <- function(url, asyncdial = FALSE, autoexit = TRUE, cleanup = TRUE, - output = FALSE, maxtasks = Inf, idletime = Inf, walltime = Inf, - timerstart = 0L, ..., tls = NULL, rs = NULL) { +daemon_legacy <- function(url, asyncdial = FALSE, autoexit = TRUE, cleanup = TRUE, + output = FALSE, maxtasks = Inf, idletime = Inf, walltime = Inf, + timerstart = 0L, ..., tls = NULL, rs = NULL) { cv <- cv() sock <- socket(protocol = "rep") diff --git a/R/daemons.R b/R/daemons.R index 48b8b5cb..000adf7c 100644 --- a/R/daemons.R +++ b/R/daemons.R @@ -546,13 +546,13 @@ wa32 <- function(url, dots, rs, tls = NULL) shQuote(sprintf("mirai::daemon(\"%s\"%s%s,rs=c(%s),dispatcher=TRUE)", url, dots, parse_tls(tls), paste0(rs, collapse = ","))) wa4 <- function(urld, dots, rs, n, urlc) - shQuote(sprintf(".libPaths(c(\"%s\",.libPaths()));mirai::dispatcher_v1(\"%s\",n=%d,rs=c(%s),monitor=\"%s\"%s)", libp(), urld, n, paste0(rs, collapse= ","), urlc, dots)) + shQuote(sprintf(".libPaths(c(\"%s\",.libPaths()));mirai::dispatcher(\"%s\",n=%d,rs=c(%s),monitor=\"%s\"%s)", libp(), urld, n, paste0(rs, collapse= ","), urlc, dots)) wa42 <- function(urld, dots, rs, n) shQuote(sprintf(".libPaths(c(\"%s\",.libPaths()));mirai::dispatcher(\"%s\",n=%d,rs=c(%s)%s)", libp(), urld, n, paste0(rs, collapse= ","), dots)) wa5 <- function(urld, dots, n, urlc, url) - shQuote(sprintf(".libPaths(c(\"%s\",.libPaths()));mirai::dispatcher_v1(\"%s\",c(\"%s\"),n=%d,monitor=\"%s\"%s)", libp(), urld, paste0(url, collapse = "\",\""), n, urlc, dots)) + shQuote(sprintf(".libPaths(c(\"%s\",.libPaths()));mirai::dispatcher(\"%s\",c(\"%s\"),n=%d,monitor=\"%s\"%s)", libp(), urld, paste0(url, collapse = "\",\""), n, urlc, dots)) wa52 <- function(urld, dots, url) shQuote(sprintf(".libPaths(c(\"%s\",.libPaths()));mirai::dispatcher(\"%s\",url=\"%s\"%s)", libp(), urld, url, dots)) diff --git a/R/dispatcher.R b/R/dispatcher.R index 12dcf802..55191d27 100644 --- a/R/dispatcher.R +++ b/R/dispatcher.R @@ -52,13 +52,20 @@ #' @param pass [default NULL] (required only if the private key supplied to #' \sQuote{tls} is encrypted with a password) For security, should be provided #' through a function that returns this value, rather than directly. +#' @param monitor unused legacy parameter - do not specify this value. #' #' @return Invisible NULL. #' #' @export #' -dispatcher <- function(host, url = NULL, n = NULL, ..., tls = NULL, pass = NULL, rs = NULL) { +dispatcher <- function(host, url = NULL, n = NULL, ..., tls = NULL, pass = NULL, + rs = NULL, monitor = NULL) { + missing(monitor) || return( + dispatcher_legacy( + host = host, url = url, n = n, ..., tls = tls, pass = pass, rs = rs, monitor = monitor + ) + ) n <- if (is.numeric(n)) as.integer(n) else length(url) n > 0L || stop(._[["missing_url"]]) @@ -205,30 +212,8 @@ dispatcher <- function(host, url = NULL, n = NULL, ..., tls = NULL, pass = NULL, } -#' Dispatcher (v1) -#' -#' This is a deprecated legacy function only present to support existing uses. -#' -#' @inheritParams dispatcher -#' @param retry [default FALSE] logical value, whether to automatically retry -#' tasks where the daemon crashes or terminates unexpectedly on the next -#' daemon instance to connect. If TRUE, the mirai will remain unresolved but -#' \code{\link{status}} will show \sQuote{online} as 0 and \sQuote{assigned} > -#' \sQuote{complete}. To cancel a task in this case, use -#' \code{saisei(force = TRUE)}. If FALSE, such tasks will be returned as -#' \sQuote{errorValue} 19 (Connection reset). -#' @param token [default FALSE] if TRUE, appends a unique 24-character token to -#' each URL path the dispatcher listens at (not applicable for TCP URLs which -#' do not accept a path). -#' @param monitor (for package internal use only) do not set this parameter. -#' -#' @return Invisible NULL. -#' -#' @keywords internal -#' @export -#' -dispatcher_v1 <- function(host, url = NULL, n = NULL, ..., retry = FALSE, token = FALSE, - tls = NULL, pass = NULL, rs = NULL, monitor = NULL) { +dispatcher_legacy <- function(host, url = NULL, n = NULL, ..., retry = FALSE, + token = FALSE, tls = NULL, pass = NULL, rs = NULL, monitor = NULL) { n <- if (is.numeric(n)) as.integer(n) else length(url) n > 0L || stop(._[["missing_url"]]) diff --git a/man/dispatcher.Rd b/man/dispatcher.Rd index 92650b9f..61d2ea03 100644 --- a/man/dispatcher.Rd +++ b/man/dispatcher.Rd @@ -4,7 +4,16 @@ \alias{dispatcher} \title{Dispatcher} \usage{ -dispatcher(host, url = NULL, n = NULL, ..., tls = NULL, pass = NULL, rs = NULL) +dispatcher( + host, + url = NULL, + n = NULL, + ..., + tls = NULL, + pass = NULL, + rs = NULL, + monitor = NULL +) } \arguments{ \item{host}{the character host URL to dial (where tasks are sent from), @@ -38,6 +47,8 @@ through a function that returns this value, rather than directly.} \item{rs}{[default NULL] the initial value of .Random.seed. This is set automatically using L'Ecuyer-CMRG RNG streams generated by the host process and should not be independently supplied.} + +\item{monitor}{unused legacy parameter - do not specify this value.} } \value{ Invisible NULL. diff --git a/man/dispatcher_v1.Rd b/man/dispatcher_v1.Rd deleted file mode 100644 index b6eb1336..00000000 --- a/man/dispatcher_v1.Rd +++ /dev/null @@ -1,73 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/dispatcher.R -\name{dispatcher_v1} -\alias{dispatcher_v1} -\title{Dispatcher (v1)} -\usage{ -dispatcher_v1( - host, - url = NULL, - n = NULL, - ..., - retry = FALSE, - token = FALSE, - tls = NULL, - pass = NULL, - rs = NULL, - monitor = NULL -) -} -\arguments{ -\item{host}{the character host URL to dial (where tasks are sent from), -including the port to connect to (and optionally for websockets, a path), -e.g. 'tcp://hostname:5555' or 'ws://10.75.32.70:5555/path'.} - -\item{url}{(optional) the character URL dispatcher should listen at, -including the port to connect to (and optionally for websockets, a path), -e.g. 'tcp://hostname:5555' or 'ws://10.75.32.70:5555/path'. -Specify 'tls+tcp://' or 'wss://' to use secure TLS connections. Daemons -should dial in to this URL.} - -\item{n}{(optional) if specified, the integer number of daemons to launch. In -this case, a local url is automatically generated.} - -\item{...}{(optional) additional arguments passed through to -\code{\link{daemon}}. These include \sQuote{asyncdial}, \sQuote{autoexit}, -and \sQuote{cleanup}.} - -\item{retry}{[default FALSE] logical value, whether to automatically retry -tasks where the daemon crashes or terminates unexpectedly on the next -daemon instance to connect. If TRUE, the mirai will remain unresolved but -\code{\link{status}} will show \sQuote{online} as 0 and \sQuote{assigned} > -\sQuote{complete}. To cancel a task in this case, use -\code{saisei(force = TRUE)}. If FALSE, such tasks will be returned as -\sQuote{errorValue} 19 (Connection reset).} - -\item{token}{[default FALSE] if TRUE, appends a unique 24-character token to -each URL path the dispatcher listens at (not applicable for TCP URLs which -do not accept a path).} - -\item{tls}{[default NULL] (required for secure TLS connections) -\strong{either} the character path to a file containing the PEM-encoded TLS -certificate and associated private key (may contain additional certificates -leading to a validation chain, with the TLS certificate first), \strong{or} -a length 2 character vector comprising [i] the TLS certificate (optionally -certificate chain) and [ii] the associated private key.} - -\item{pass}{[default NULL] (required only if the private key supplied to -\sQuote{tls} is encrypted with a password) For security, should be provided -through a function that returns this value, rather than directly.} - -\item{rs}{[default NULL] the initial value of .Random.seed. This is set -automatically using L'Ecuyer-CMRG RNG streams generated by the host process -and should not be independently supplied.} - -\item{monitor}{(for package internal use only) do not set this parameter.} -} -\value{ -The regenerated character URL upon success, or else NULL. -} -\description{ -This is a deprecated legacy function only present to support existing uses. -} -\keyword{internal} diff --git a/tests/tests.R b/tests/tests.R index d6e2f417..8e634391 100644 --- a/tests/tests.R +++ b/tests/tests.R @@ -134,6 +134,7 @@ connection && .Platform[["OS.type"]] != "windows" && { test_identical(call_mirai(mp)[["x"]][["data"]], "ab") test_true(all(mirai_map(data.frame(1:3, 3:1), sum, .args = list(3L))[.flat] == 7L)) test_true(all(mirai_map(list(c(a = 1, b = 1, c = 1), 3), sum)[.flat] == 3)) + test_zero(daemons(0L)) } # parallel cluster tests library(parallel) @@ -224,6 +225,7 @@ connection && .Platform[["OS.type"]] != "windows" && Sys.getenv("NOT_CRAN") == " test_equal(daemons()[["connections"]], 2L) test_type("list", res <- mirai_map(c(1,1), rnorm)[.progress]) test_true(res[[1L]] != res[[2L]]) + test_zero(daemons(0L)) } # TLS tests connection && Sys.getenv("NOT_CRAN") == "true" && {