Skip to content

Commit

Permalink
Default to most recent cloud checks (#286)
Browse files Browse the repository at this point in the history
* Default to most recent cloud checks

Closes #279

* Make `pkg` the second argument

* Document the new argument and behaviour

* Reword message

* Account for lack of `revdep/cloud.noindex`

* Create subdir for job_id in cloud_check()

* Create job_id's subdir unconditionally

OK for pre-exists case, because `showWarnings = FALSE`
  • Loading branch information
jennybc authored Dec 9, 2020
1 parent db3bc3b commit b2fd95b
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 33 deletions.
57 changes: 38 additions & 19 deletions R/cloud.R
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ calc_eta <- function(creation_time, current_time, running, completed, total) {
#' @family cloud
#' @inheritParams cloud_report
#' @export
cloud_fetch_results <- function(job_id = cloud_job(), pkg = ".") {
cloud_fetch_results <- function(job_id = cloud_job(pkg = pkg), pkg = ".") {
pkg <- pkg_check(pkg)
cloud <- dir_find(pkg, "cloud")

Expand Down Expand Up @@ -199,7 +199,10 @@ cloud_check <- function(pkg = ".", tarball = NULL, revdep_packages = NULL, r_ver

cli_alert("Run {.fun cloud_status} to monitor job status")

cloud_job(job_id)
cloud_job(job_id = job_id)
cloud <- dir_find(pkg, "cloud")
out_dir <- file.path(cloud, job_id)
dir.create(out_dir, showWarnings = FALSE, recursive = TRUE)

invisible(job_id)
}
Expand Down Expand Up @@ -352,7 +355,7 @@ cloud_compare <- function(pkg) {
#' @inheritParams cloud_report
#' @family cloud
#' @export
cloud_summary <- function(job_id = cloud_job(), pkg = ".") {
cloud_summary <- function(job_id = cloud_job(pkg = pkg), pkg = ".") {
results <- cloud_results(job_id = job_id, pkg = pkg)
structure(
results,
Expand All @@ -366,7 +369,7 @@ cloud_summary <- function(job_id = cloud_job(), pkg = ".") {
#' @inheritParams cloud_report
#' @family cloud
#' @export
cloud_details <- function(job_id = cloud_job(), revdep, pkg = ".") {
cloud_details <- function(job_id = cloud_job(pkg = pkg), revdep, pkg = ".") {
pkg <- pkg_check(pkg)
cloud <- dir_find(pkg, "cloud")

Expand All @@ -386,7 +389,7 @@ cloud_details <- function(job_id = cloud_job(), revdep, pkg = ".") {
#' @inheritParams revdep_report
#' @family cloud
#' @export
cloud_report <- function(job_id = cloud_job(), pkg = ".", file = "", all = FALSE, results = NULL, failures = TRUE) {
cloud_report <- function(job_id = cloud_job(pkg = pkg), pkg = ".", file = "", all = FALSE, results = NULL, failures = TRUE) {
pkg <- pkg_check(pkg)
root <- dir_find(pkg, "root")

Expand Down Expand Up @@ -417,7 +420,7 @@ cloud_report <- function(job_id = cloud_job(), pkg = ".", file = "", all = FALSE

#' @rdname cloud_report
#' @export
cloud_report_summary <- function(job_id = cloud_job(), file = "", all = FALSE, pkg = ".", results = NULL) {
cloud_report_summary <- function(job_id = cloud_job(pkg = pkg), file = "", all = FALSE, pkg = ".", results = NULL) {
if (is.null(results)) {
results <- cloud_results(job_id, pkg)
}
Expand Down Expand Up @@ -451,7 +454,7 @@ cloud_report_summary <- function(job_id = cloud_job(), file = "", all = FALSE, p

#' @rdname cloud_report
#' @export
cloud_report_problems <- function(job_id = cloud_job(), pkg = ".", file = "", all = FALSE, results = NULL) {
cloud_report_problems <- function(job_id = cloud_job(pkg = pkg), pkg = ".", file = "", all = FALSE, results = NULL) {
if (is.null(results)) {
results <- cloud_results(job_id, pkg)
}
Expand All @@ -460,7 +463,7 @@ cloud_report_problems <- function(job_id = cloud_job(), pkg = ".", file = "", al

#' @rdname cloud_report
#' @export
cloud_report_failures <- function(job_id = cloud_job(), pkg = ".", file = "", results = NULL) {
cloud_report_failures <- function(job_id = cloud_job(pkg = pkg), pkg = ".", file = "", results = NULL) {
if (is.null(results)) {
results <- cloud_results(job_id, pkg)
}
Expand All @@ -469,7 +472,7 @@ cloud_report_failures <- function(job_id = cloud_job(), pkg = ".", file = "", re

#' @rdname cloud_report
#' @export
cloud_report_cran <- function(job_id = cloud_job(), pkg = ".", results = NULL) {
cloud_report_cran <- function(job_id = cloud_job(pkg = pkg), pkg = ".", results = NULL) {
if (is.null(results)) {
results <- cloud_results(job_id, pkg)
}
Expand All @@ -483,7 +486,7 @@ cloud_report_cran <- function(job_id = cloud_job(), pkg = ".", results = NULL) {
#' @family cloud
#' @keywords internal
#' @export
cloud_results <- function(job_id = cloud_job(), pkg = ".") {
cloud_results <- function(job_id = cloud_job(pkg = pkg), pkg = ".") {
pkg <- pkg_check(pkg)
cloud <- dir_find(pkg, "cloud")

Expand All @@ -504,7 +507,7 @@ cloud_results <- function(job_id = cloud_job(), pkg = ".") {
#' @inheritParams cloud_report
#' @inherit revdep_email
#' @export
cloud_email <- function(type = c("broken", "failed"), job_id = cloud_job(), pkg = ".", packages = NULL, draft = FALSE) {
cloud_email <- function(type = c("broken", "failed"), job_id = cloud_job(pkg = pkg), pkg = ".", packages = NULL, draft = FALSE) {
type <- match.arg(type)

package_results <- cloud_results(job_id, pkg)
Expand All @@ -527,18 +530,34 @@ cloud_email <- function(type = c("broken", "failed"), job_id = cloud_job(), pkg

#' Return the current cloud job
#'
#' This is automatically set by [cloud_check()] and only lasts for the current R session.
#' The `job_id` is automatically set by [cloud_check()] and is remembered for
#' the duration of the current R session. If there is no active `job_id`, but
#' there are local cloud check results, `job_id` is inferred from the most
#' recently modified cloud check results.
#'
#' @param job_id If not `NULL`, sets the active `job_id` to the input.
#' @inheritParams cloud_report
#' @export
cloud_job <- function(job_id = NULL) {
if (!is.null(job_id)) {
cloud_data$job_id <- job_id
cloud_job <- function(job_id = NULL, pkg = ".") {
cloud_data$job_id <- job_id %||% cloud_data$job_id
if (!is.null(cloud_data$job_id)) {
return(invisible(cloud_data$job_id))
}

if (is.null(cloud_data$job_id)) {
stop("No current job, please specify the `job_id` explicitly, or run a job with `cloud_check()`", call. = FALSE)
pkg <- pkg_check(pkg)
cloud <- dir_find(pkg, "cloud")
if (dir.exists(cloud)) {
cloud_dirs <- list.dirs(cloud, recursive = FALSE)
} else {
cloud_dirs <- character()
}
if (length(cloud_dirs) < 1) {
stop("Can't find any previous `cloud_check()` results locally, can't discover `job_id`", call. = FALSE)
}

latest <- cloud_dirs[which.max(file.info(cloud_dirs)$mtime)]
cloud_data$job_id <- basename(latest)
cli_alert_success("Most recent cloud job {.arg job_id}: {.val {cloud_data$job_id}}")
invisible(cloud_data$job_id)
}

Expand Down Expand Up @@ -666,7 +685,7 @@ cloud_job_mapping <- function(job_id = cloud_job()) {
#' @family cloud
#' @returns A character vector with the names of broken packages, to be passed to `cloud_check()`.
#' @export
cloud_broken <- function(job_id = cloud_job(), pkg = ".", install_failures = FALSE, timeout_failures = FALSE) {
cloud_broken <- function(job_id = cloud_job(pkg = pkg), pkg = ".", install_failures = FALSE, timeout_failures = FALSE) {
results <- cloud_results(job_id = job_id, pkg = pkg)
broken <- map_lgl(results, is_broken, install_failures, timeout_failures)

Expand All @@ -675,7 +694,7 @@ cloud_broken <- function(job_id = cloud_job(), pkg = ".", install_failures = FAL

#' @rdname cloud_broken
#' @export
cloud_failed <- function(job_id = cloud_job(), pkg = ".") {
cloud_failed <- function(job_id = cloud_job(pkg = pkg), pkg = ".") {
failed_indexes <- cloud_job_list(job_id, status = "FAILED")$jobSummaryList$arrayProperties$index
mapping <- cloud_job_mapping(job_id)

Expand Down
4 changes: 2 additions & 2 deletions man/cloud_broken.Rd

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

2 changes: 1 addition & 1 deletion man/cloud_details.Rd

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

2 changes: 1 addition & 1 deletion man/cloud_email.Rd

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

2 changes: 1 addition & 1 deletion man/cloud_fetch_results.Rd

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

9 changes: 7 additions & 2 deletions man/cloud_job.Rd

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

10 changes: 5 additions & 5 deletions man/cloud_report.Rd

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

2 changes: 1 addition & 1 deletion man/cloud_results.Rd

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

2 changes: 1 addition & 1 deletion man/cloud_summary.Rd

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

0 comments on commit b2fd95b

Please sign in to comment.