diff --git a/.github/workflows/check-load-prodes.yaml b/.github/workflows/check-load-prodes.yaml index 7f918557..aad6655c 100644 --- a/.github/workflows/check-load-prodes.yaml +++ b/.github/workflows/check-load-prodes.yaml @@ -17,6 +17,13 @@ jobs: with: r-version: 'release' use-public-rspm: true + + - name: Free disk space + run: | + sudo rm -rf /usr/share/dotnet /usr/local/lib/android /opt/ghc + sudo apt-get clean + df -h + - name: System dependencies (sf/units) run: | diff --git a/actions/scripts/check_all_loads.R b/actions/scripts/check_all_loads.R index a1d90034..909f2829 100644 --- a/actions/scripts/check_all_loads.R +++ b/actions/scripts/check_all_loads.R @@ -11,12 +11,22 @@ if (!requireNamespace("datazoom.amazonia", quietly = TRUE)) { } library(datazoom.amazonia) +# Avoid iterative authentication in CI (googledrive) +if (requireNamespace("googledrive", quietly = TRUE)) { + options(gargle_oauth_cache = FALSE) + googledrive::drive_deauth() +} + # Config TIME_PERIOD <- 2020 LANGUAGE <- "pt" RAW_DATA <- FALSE GEO_LEVEL <- "state" +time_period_by_fn <- list( + load_ips = 2023 +) + datasets_by_fn <- list( @@ -127,18 +137,9 @@ call_with_geo <- function(fn, args, geo_level = "state") { } # tenta com geo_level = "state" - res <- tryCatch( - do.call(fn, c(args, list(geo_level = geo_level))), - error = function(e) e - ) - - # se funcionou, retorna - if (!inherits(res, "error")) { - return(res) - } + res <- do.call(fn, c(args, list(geo_level = geo_level))) - # fallback: tenta sem geo_level - do.call(fn, args) + return(res) } @@ -190,54 +191,69 @@ for (fn_name in get_fns) { args <- list() if ("dataset" %in% arg_names) args$dataset <- ds - if ("time_period" %in% arg_names) args$time_period <- TIME_PERIOD + if ("time_period" %in% arg_names) { + args$time_period <- if (!is.null(time_period_by_fn[[fn_name]])) { + time_period_by_fn[[fn_name]] + } else {TIME_PERIOD} + } if ("raw_data" %in% arg_names) args$raw_data <- RAW_DATA if ("language" %in% arg_names) args$language <- LANGUAGE out <- NULL + warn_msgs <- character(0) res <- tryCatch( - { - out <- call_with_geo(fn, args, geo_level = GEO_LEVEL) - - if (!is.null(out) && (is.data.frame(out) || inherits(out, "tbl_df"))) { + withCallingHandlers( + { + out <- call_with_geo(fn, args, geo_level = GEO_LEVEL) "OK" - } else { - "WEIRD" + }, + warning = function(w) { + warn_msgs <<- c(warn_msgs, conditionMessage(w)) + invokeRestart("muffleWarning") } - }, - warning = function(w) paste("WARN:", conditionMessage(w)), - error = function(e) paste("ERROR:", conditionMessage(e)) + ), + error = function(e) paste("ERROR:", conditionMessage(e)) ) - status <- if (identical(res, "OK")) { - "OK" - } else if (identical(res, "WEIRD")) { - "WEIRD" - } else if (startsWith(res, "WARN:")) { + # decide status + status <- if (startsWith(res, "ERROR:")) { + "FAIL" + } else if (length(warn_msgs) > 0) { "WARN" } else { - "FAIL" + "OK" } - # dimensões (só faz sentido se out for data.frame/tibble) + # dims n_rows <- NA_integer_ n_cols <- NA_integer_ if (!is.null(out) && (is.data.frame(out) || inherits(out, "tbl_df"))) { n_rows <- nrow(out) n_cols <- ncol(out) + } else if (status != "FAIL") { + status <- "WEIRD" } - # se rodou "OK" (ou até "WARN") mas retornou vazio, marque como EMPTY - # (ajuste a regra se quiser: ex. considerar vazio só quando n_rows == 0) + # empty if (status %in% c("OK", "WARN") && !is.na(n_rows) && n_rows == 0) { status <- "EMPTY" - if (!startsWith(res, "WARN:")) { - res <- "EMPTY: data.frame retornado com 0 linhas" - } } - msg <- if (status %in% c("WARN", "FAIL", "WEIRD", "EMPTY")) res else "" + # mensagem + msg <- "" + if (status == "FAIL") { + msg <- res + } else if (status %in% c("WARN","WEIRD","EMPTY")) { + msg <- paste(c(warn_msgs, if (status=="EMPTY") "EMPTY: data.frame retornado com 0 linhas" else NULL), collapse = " | ") + } + + # Classificar falta de disco como FAIL (mesmo vindo como warning) + # if (grepl("Estimated disk space needed", msg, fixed = TRUE)) { + # status <- "FAIL" + # msg <- paste("DISK:", msg) + # } + results <- rbind(results, data.frame( function_name = fn_name,