Skip to content

Commit

Permalink
move autometric to Suggests:
Browse files Browse the repository at this point in the history
  • Loading branch information
wlandau committed Nov 14, 2024
1 parent b1c3750 commit 1937e52
Show file tree
Hide file tree
Showing 15 changed files with 52 additions and 23 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ Authors@R: c(
Depends:
R (>= 4.0.0)
Imports:
autometric (>= 0.1.0),
cli (>= 3.1.0),
data.table,
getip,
Expand All @@ -58,6 +57,7 @@ Imports:
tools,
utils
Suggests:
autometric (>= 0.1.0),
knitr (>= 1.30),
markdown (>= 1.1),
rmarkdown (>= 2.4),
Expand Down
2 changes: 0 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ export(num_range)
export(one_of)
export(starts_with)
importFrom(R6,R6Class)
importFrom(autometric,log_start)
importFrom(autometric,log_stop)
importFrom(cli,cli_progress_bar)
importFrom(cli,cli_progress_done)
importFrom(cli,cli_progress_update)
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* Look for crashes of all workers in `rotate()` instead of looking for crashes of a specific worker in `launch()` (#189).
* Add a `crashes()` launcher method to allow plugins to detect and respond to crashes more easily.
* Change default `seconds_idle` to 300.
* Move `autometric` to `Suggests:`.

# crew 0.10.1

Expand Down
6 changes: 4 additions & 2 deletions R/crew_eval.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@ crew_eval <- function(
if (anyNA(name)) {
name <- basename(tempfile(pattern = "unnamed_task_"))
}
autometric::log_phase_set(phase = name)
on.exit(autometric::log_phase_reset())
if (installed_autometric) {
autometric::log_phase_set(phase = name)
on.exit(autometric::log_phase_reset())
}
old_algorithm <- RNGkind()[1L]
old_seed <- .subset2(.GlobalEnv, ".Random.seed")
if (!is.null(algorithm) || !is.null(seed)) {
Expand Down
15 changes: 9 additions & 6 deletions R/crew_options_metrics.R
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
#' @title Options for logging resource usage metrics.
#' @export
#' @family options
#' @description If a [crew_options_metrics()] object is
#' supplied to the `options_metrics` argument of a `crew`
#' controller function, then the `autometric` R package will
#' record resource usage metrics (such as CPU and memory usage)
#' for each running worker. Logging happens in
#' the background (through a detached POSIX) so as not to disrupt
#' @description [crew_options_metrics()] configures the

Check warning on line 4 in R/crew_options_metrics.R

View workflow job for this annotation

GitHub Actions / lint

file=R/crew_options_metrics.R,line=4,col=56,[trailing_whitespace_linter] Trailing whitespace is superfluous.
#' `crew` to record resource usage metrics (such as CPU and memory usage)
#' for each running worker.
#' To be activate resource usage logging,
#' the `autometric` R package version 0.1.0 or higher
#' must be installed.
#'
#' Logging happens in the background (through a detached POSIX)
#' so as not to disrupt
#' the R session. On Unix-like systems, [crew_options_metrics()]
#' can specify `/dev/stdout` or `/dev/stderr` as the log files, which will
#' redirect output to existing logs you are already using.
Expand Down
1 change: 0 additions & 1 deletion R/crew_package.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#' [`rrq`](https://mrc-ide.github.io/rrq/),
#' [`clustermq`](https://mschubert.github.io/clustermq/),
#' and [`batchtools`](https://mllg.github.io/batchtools/).
#' @importFrom autometric log_start log_stop
#' @importFrom cli cli_progress_bar cli_progress_done cli_progress_update
#' @importFrom data.table rbindlist
#' @importFrom getip getip
Expand Down
5 changes: 4 additions & 1 deletion R/crew_worker.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,17 @@
#' @param options_metrics Either `NULL` to opt out of resource metric logging
#' for workers, or an object from [crew_options_metrics()] to enable
#' and configure resource metric logging for workers.
#' For resource logging to run,
#' the `autometric` R package version 0.1.0 or higher
#' must be installed.
crew_worker <- function(
settings,
launcher,
worker,
instance,
options_metrics = crew::crew_options_metrics()
) {
if (!is.null(options_metrics$path)) {
if (installed_autometric && !is.null(options_metrics$path)) {
pids <- Sys.getpid()
names(pids) <- sprintf("crew_worker_%s_%s_%s", launcher, worker, instance)
autometric::log_start(
Expand Down
5 changes: 5 additions & 0 deletions R/utils_packages.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,8 @@ load_packages <- function(packages, library) {
)
crew_assert(all(out), message = msg)
}

installed_autometric <- rlang::is_installed(
pkg = "autometric",
version = "0.1.0"
)
5 changes: 4 additions & 1 deletion man/crew_controller_local.Rd

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

5 changes: 4 additions & 1 deletion man/crew_launcher.Rd

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

5 changes: 4 additions & 1 deletion man/crew_launcher_local.Rd

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

15 changes: 9 additions & 6 deletions man/crew_options_metrics.Rd

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

5 changes: 4 additions & 1 deletion man/crew_worker.Rd

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

2 changes: 2 additions & 0 deletions tests/testthat/test-crew_controller_local.R
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ crew_test("exit status and code", {
crew_test("crew_controller_local() resource usage metric logging", {
skip_on_cran()
skip_on_os("windows")
skip_if_not_installed("autometric", minimum_version = "0.1.0")
log <- tempfile()
x <- crew_controller_local(
seconds_idle = 360,
Expand Down Expand Up @@ -296,6 +297,7 @@ crew_test("crew_controller_local() resource usage metric logging", {
crew_test("crew_controller_local() resource usage metrics with stdout", {
skip_on_cran()
skip_on_os("windows")
skip_if_not_installed("autometric", minimum_version = "0.1.0")
log <- tempfile()
x <- crew_controller_local(
seconds_idle = 360,
Expand Down
1 change: 1 addition & 0 deletions tests/testthat/test-crew_worker.R
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ crew_test("crew_worker() can run mirai tasks and assigns env vars", {
crew_test("crew_worker() metrics logging to a directory", {
skip_on_cran()
skip_on_os("windows")
skip_if_not_installed("autometric", minimum_version = "0.1.0")
envvars <- c("CREW_LAUNCHER", "CREW_WORKER", "CREW_INSTANCE")
previous <- Sys.getenv(envvars)
Sys.unsetenv(envvars)
Expand Down

0 comments on commit 1937e52

Please sign in to comment.