feat: account for removed packages in metadata

This commit is contained in:
Patrick Schratz 2024-11-17 22:03:37 +01:00
commit 8c8a8c0a98
Signed by: pat-s
GPG key ID: 3C6318841EF78925
2 changed files with 18 additions and 4 deletions

View file

@ -20,8 +20,8 @@ store_build_metadata <- function(
} else if (nrow(existing_entries) >= 1 && force) {
cli::cli_alert_info("{.fun store_build_metadata}: Force overwriting build metadata for {.pkg {package_name}} {.field {tag}} ({platform}) because {.code force = TRUE} was set.")
DBI::dbExecute(con, "UPDATE single_builds SET timestamp = $1, error_occurred = $2, error_text = $3, duration = $4, size = $5 WHERE name = $6 and tag = $7 and platform = $8",
params = list(format(Sys.time(), "%Y-%m-%d %H:%M:%S"), error_occurred, error, build_duration, size, package_name, tag, platform)
DBI::dbExecute(con, "UPDATE single_builds SET timestamp = $1, error_occurred = $2, error_text = $3, duration = $4, size = $5, removed = $9 WHERE name = $6 and tag = $7 and platform = $8",
params = list(format(Sys.time(), "%Y-%m-%d %H:%M:%S"), error_occurred, error, build_duration, size, package_name, tag, platform, FALSE)
)
} else if (nrow(existing_entries) == 0) {
cli::cli_alert("{.fun store_build_metadata}: Storing build metadata for {.pkg {package_name}} {.field {tag}}.")
@ -35,7 +35,8 @@ store_build_metadata <- function(
error_text = error,
size = size,
timestamp = format(Sys.time(), "%Y-%m-%d %H:%M:%S"),
duration = build_duration
duration = build_duration,
removed = FALSE
)
# Write the data frame to the SQLite database
dbWriteTable(con, "single_builds", metadata, append = TRUE)
@ -45,6 +46,18 @@ store_build_metadata <- function(
return(invisible(TRUE))
}
remove_from_metadata <- function(package) {
con <- DBI::dbConnect(RPostgres::Postgres(),
dbname = "build_metadata", host = "r-binaries.devxy.io",
port = 15432, user = "r_binaries", password = Sys.getenv("PGPASS"),
sslmode = "require"
)
DBI::dbExecute(con, "UPDATE single_builds SET removed = true WHERE name = $1",
params = list(package)
)
}
#' @importFrom DBI dbConnect dbDisconnect dbWriteTable dbGetQuery dbExecute dbListTables
#' @importFrom dplyr group_by summarise filter n
build_metadata_summary <- function(package_name, platform) {
@ -94,7 +107,6 @@ build_metadata_summary <- function(package_name, platform) {
"', package_name = '", package_name,
"', platform = '", platform, "'",
"', arch = '", platform, "'",
))
} else {
dbWriteTable(con, "metadata_summary", summary)

View file

@ -84,6 +84,8 @@ process_cran_updates <- function(
if (length(files_filtered) > 0) {
s3fs::s3_file_delete(files_filtered)
cli::cli_alert_success("{.fun process_cran_updates}: Successfully removed {.pkg {basename(files_filtered)}} from S3.")
remove_from_metadata(.x)
cli::cli_alert_success("{.fun process_cran_updates}: Successfully set {.pkg {basename(files_filtered)}} as 'removed' in metadata table.")
} else {
cli::cli_alert("{.fun process_cran_updates}: No tarballs found for package {.pkg {.x}} - already removed?")
}