Skip to content

Commit

Permalink
Make metadata easier to use.
Browse files Browse the repository at this point in the history
Test that all fields are atomic. May have to change this at some point, if we ever add non-atomic fields on purpose.
  • Loading branch information
natemcintosh committed Dec 11, 2024
1 parent 66ac3ea commit af863f2
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 8 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# CFAEpiNow2Pipeline (development version)

* Change formatting of metadata values to be atomic.
* Add `blob_storage_container` as a field to the metadata.
* Use empty string for paths when non-existant.
* Populated the default values of the metadata to be saved.
* Creating a Config class to make syncing configuration differences easier.
* Add a JSON reader for the Config class.
Expand Down
15 changes: 11 additions & 4 deletions R/pipeline.R
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ orchestrate_pipeline <- function(config_path,
# `pipeline_success` is set to false, which will be stored in the
# metadata in the next PR.
pipeline_success <- rlang::try_fetch(
execute_model_logic(config, output_dir),
execute_model_logic(config, output_dir, blob_storage_container),
error = function(con) {
cli::cli_warn("Pipeline run failed",
parent = con,
Expand Down Expand Up @@ -152,7 +152,7 @@ orchestrate_pipeline <- function(config_path,
#'
#' @rdname pipeline
#' @export
execute_model_logic <- function(config, output_dir) {
execute_model_logic <- function(config, output_dir, blob_storage_container) {
cases_df <- read_data(
data_path = config@data@path,
disease = config@disease,
Expand Down Expand Up @@ -218,7 +218,7 @@ execute_model_logic <- function(config, output_dir) {
data_path = ifelse(
# is_empty checks for NULL and empty data structures
rlang::is_empty(config@data@path),
config@data@path, ""
"", config@data@path
),
model = config@model,
disease = config@disease,
Expand All @@ -227,7 +227,14 @@ execute_model_logic <- function(config, output_dir) {
production_date = config@production_date,
max_reference_date = config@max_reference_date,
min_reference_date = config@min_reference_date,
exclusions = config@exclusions@path,
exclusions = ifelse(
rlang::is_empty(config@exclusions@path),
"", config@exclusions@path
),
blob_storage_container = ifelse(
rlang::is_empty(blob_storage_container),
"", blob_storage_container
),
run_at = format(Sys.time(), "%Y-%m-%dT%H:%M:%S%z")
)

Expand Down
5 changes: 4 additions & 1 deletion R/write_output.R
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@ write_model_outputs <- function(
model_path = model_path
)
)
jsonlite::write_json(metadata, metadata_path, pretty = TRUE)
jsonlite::write_json(
metadata, metadata_path,
pretty = TRUE, auto_unbox = TRUE
)
cli::cli_alert_success("Wrote metadata to {.path {metadata_path}}")
},
error = function(cnd) {
Expand Down
2 changes: 1 addition & 1 deletion man/pipeline.Rd

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

5 changes: 5 additions & 0 deletions tests/testthat/helper-expect_pipeline_files_written.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,9 @@ expect_pipeline_files_written <- function(
expect_true(file.exists(metadata_path))
metadata <- jsonlite::read_json(metadata_path)
expect_gt(length(metadata), 0)

# Check that each field passes `rlang::is_atomic()`
for (field in names(metadata)) {
expect_true(rlang::is_atomic(metadata[[field]]))
}
}
6 changes: 4 additions & 2 deletions tests/testthat/test-pipeline.R
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ test_that("Process pipeline produces expected outputs and returns success", {
# Act
pipeline_success <- execute_model_logic(
config = config,
output_dir = output_dir
output_dir = output_dir,
blob_storage_container = "blah"
)
expect_true(pipeline_success)

Expand Down Expand Up @@ -107,7 +108,8 @@ test_that("Runs on config from generator as of 2024-11-26", {
# Act
pipeline_success <- execute_model_logic(
config = config,
output_dir = output_dir
output_dir = output_dir,
blob_storage_container = "blah"
)
expect_true(pipeline_success)

Expand Down

0 comments on commit af863f2

Please sign in to comment.