Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/workflows/check-load-prodes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
84 changes: 50 additions & 34 deletions actions/scripts/check_all_loads.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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)
}


Expand Down Expand Up @@ -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,
Expand Down