move sqlite to s3, mature metadata summary functions
This commit is contained in:
parent
63a742d775
commit
d983f391fb
1 changed files with 147 additions and 50 deletions
|
|
@ -73,11 +73,12 @@ build_binary_package <- function(package_name, tag = NULL, codename = NULL,
|
|||
tryCatch(
|
||||
{
|
||||
p()
|
||||
build_single_tag(x, y, dir_out_bin, local_clone_dir)
|
||||
build_single_tag(x, y, dir_out_bin, local_clone_dir, platform = platform)
|
||||
store_build_metadata(x, y, platform, FALSE)
|
||||
},
|
||||
error = function(e) {
|
||||
message("Error in processing package ", x, " with tag ", y, ": ")
|
||||
local_clone_dir_single <- sprintf("%s/%s_%s", local_clone_dir, x, y)
|
||||
unlink(local_clone_dir_single, force = TRUE, recursive = TRUE)
|
||||
store_build_metadata(x, y, platform, TRUE)
|
||||
}
|
||||
|
|
@ -90,29 +91,6 @@ build_binary_package <- function(package_name, tag = NULL, codename = NULL,
|
|||
total_build_time <- round(Sys.time() - t1, 2)
|
||||
cli::cli_alert_info("Execution time for {.pkg {package_name[[1]]}} ({length(tag)} tags): {.strong {total_build_time} {units(difftime(Sys.time(), t1))}}.")
|
||||
|
||||
# add average_build_time_per_tag to metadata summary table
|
||||
average_build_time_per_tag <- round(total_build_time / length(tag), 2)
|
||||
con <- dbConnect(RSQLite::SQLite(), dbname = "metadata.db")
|
||||
# Check if the entry exists in the metadata_summary table
|
||||
# Check if a valid entry exists in the metadata_summary table
|
||||
entry <- dbGetQuery(con, paste0(
|
||||
"SELECT average_build_time_per_tag FROM metadata_summary WHERE package_name = '", package_name[[1]],
|
||||
"' AND platform = '", platform, "'"
|
||||
))
|
||||
# If the entry does not exist or is not valid, entry will be NULL or NA
|
||||
entry_exists <- !is.null(entry$average_build_time_per_tag) && !is.na(entry$average_build_time_per_tag)
|
||||
|
||||
# If the entry does not exist, update the average_build_time_per_tag
|
||||
if (!entry_exists) {
|
||||
dbExecute(con, paste0(
|
||||
"UPDATE metadata_summary SET average_build_time_per_tag = ", average_build_time_per_tag,
|
||||
" WHERE package_name = '", package_name[[1]], "' AND platform = '", platform, "'"
|
||||
))
|
||||
}
|
||||
|
||||
cli::cli_alert_info("{.fun build_binary_package}: Building/updating metadata summary for {.pkg {package_name[[1]]}}.")
|
||||
build_metadata_summary(package_name[[1]], platform)
|
||||
|
||||
return(invisible(TRUE))
|
||||
}
|
||||
|
||||
|
|
@ -144,9 +122,11 @@ install_package_system_dependencies <- function(package_name,
|
|||
|
||||
#' @importFrom cli cli_alert_info
|
||||
#' @importFrom pkgbuild build
|
||||
build_single_tag <- function(package_name, tag = NULL,
|
||||
dir_out_bin,
|
||||
local_clone_dir) {
|
||||
build_single_tag <- function(
|
||||
package_name, tag = NULL,
|
||||
platform,
|
||||
dir_out_bin,
|
||||
local_clone_dir) {
|
||||
cli::cli_alert_info("{.fun build_single_tag}: 1. Cloning package {.pkg {package_name}} with tag {.strong {tag}}.")
|
||||
|
||||
local_clone_dir_single <- sprintf("%s/%s_%s", local_clone_dir, package_name, tag)
|
||||
|
|
@ -159,6 +139,7 @@ build_single_tag <- function(package_name, tag = NULL,
|
|||
|
||||
cli::cli_alert_info("{.fun build_single_tag}: 2. Building package {.pkg {package_name}} with tag {.strong {tag}}.")
|
||||
|
||||
t1 <- Sys.time()
|
||||
pkgbuild::build(
|
||||
path = sprintf("%s", local_clone_dir_single),
|
||||
binary = TRUE, vignettes = FALSE,
|
||||
|
|
@ -179,4 +160,28 @@ build_single_tag <- function(package_name, tag = NULL,
|
|||
|
||||
cli::cli_alert_info("{.fun build_single_tag}: 4. Removing {.path {local_clone_dir_single}}.")
|
||||
unlink(local_clone_dir_single, force = TRUE, recursive = TRUE)
|
||||
|
||||
total_build_time <- round(Sys.time() - t1, 2)
|
||||
|
||||
s3 <- paws.storage::s3(config = list(
|
||||
endpoint = "https://s3.eu-central-003.backblazeb2.com",
|
||||
region = "eu-central-003"
|
||||
))
|
||||
db_local <- s3$get_object(Bucket = "devxy-arm64-r-binaries-db", Key = "metadata.sqlite")
|
||||
writeBin(db_local$Body, "/tmp/metadata.sqlite")
|
||||
|
||||
con <- dbConnect(RSQLite::SQLite(), dbname = "/tmp/metadata.sqlite")
|
||||
dbExecute(con, "BEGIN TRANSACTION")
|
||||
# Create an index on the package_name and tag columns
|
||||
dbExecute(con, sprintf(
|
||||
"UPDATE metadata set build_time = '%s' where package_name = '%s' and platform = '%s' and tag = '%s'",
|
||||
total_build_time, package_name, platform, tag
|
||||
))
|
||||
dbExecute(con, "COMMIT")
|
||||
dbDisconnect(con)
|
||||
|
||||
invisible(s3$put_object(
|
||||
Bucket = "devxy-arm64-r-binaries-db", Key = "metadata.sqlite",
|
||||
Body = "/tmp/metadata.sqlite"
|
||||
))
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue