From 0a66a91e343ebdc32ef8c340c4c0ecb4da2237c9 Mon Sep 17 00:00:00 2001 From: giorgiacek Date: Fri, 20 Dec 2024 12:05:36 -0500 Subject: [PATCH 1/5] cache-control header added for test --- inst/TMP/TMP_local_setup.R | 3 +++ inst/plumber/v1/endpoints.R | 4 ++++ 2 files changed, 7 insertions(+) create mode 100644 inst/TMP/TMP_local_setup.R diff --git a/inst/TMP/TMP_local_setup.R b/inst/TMP/TMP_local_setup.R new file mode 100644 index 00000000..3ac5daac --- /dev/null +++ b/inst/TMP/TMP_local_setup.R @@ -0,0 +1,3 @@ +# Set-up to test locally + +devtools::install(".") diff --git a/inst/plumber/v1/endpoints.R b/inst/plumber/v1/endpoints.R index 7729c652..c88873e5 100644 --- a/inst/plumber/v1/endpoints.R +++ b/inst/plumber/v1/endpoints.R @@ -179,6 +179,10 @@ function(req, res) { res$setHeader("Access-Control-Allow-Origin", "*") + + # Set Cache-Control header to allow caching + res$setHeader("Cache-Control", "public, max-age=7200") + # Set max-age to 48hours (specified in seconds) # res$setHeader("Cache-Control", # "max-age=172800") From b4841f51ce245a85b1682dc603a87b1c43654b8c Mon Sep 17 00:00:00 2001 From: giorgiacek Date: Fri, 20 Dec 2024 13:51:09 -0500 Subject: [PATCH 2/5] local setup to run as source --- inst/TMP/TMP_local_setup.R | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/inst/TMP/TMP_local_setup.R b/inst/TMP/TMP_local_setup.R index 3ac5daac..1d42337e 100644 --- a/inst/TMP/TMP_local_setup.R +++ b/inst/TMP/TMP_local_setup.R @@ -1,3 +1,31 @@ -# Set-up to test locally +# Set-up to test locally within a given branch + +# 1. Install the package in given branch if you need you, then hashtag and run as source. +#library(devtools) +#devtools::install_github("PIP-Technical-Team/pipapi@no-store") + +# 2. Load the packages +library(pipapi) +library(fastverse) + +# 3. Prepare lkup +force <- FALSE +if (!"lkups" %in% ls() || isTRUE(force)) { + data_dir <- Sys.getenv("PIPAPI_DATA_ROOT_FOLDER_LOCAL") |> + fs::path() + fs::dir_ls(data_dir, recurse = FALSE) +} + + +latest_version <- + pipapi:::available_versions(data_dir) |> + max() + +lkups <- pipapi:::create_versioned_lkups(data_dir, + vintage_pattern = latest_version) +lkup <- lkups$versions_paths[[lkups$latest_release]] + +# 4. Start the api +pipapi:::start_api(api_version = "v1", port = 8080) + -devtools::install(".") From bf2d186058feba1ffe10552f32bfab2811323dd6 Mon Sep 17 00:00:00 2001 From: giorgiacek Date: Mon, 20 Jan 2025 12:11:22 -0500 Subject: [PATCH 3/5] small change in local set-up --- inst/TMP/TMP_local_setup.R | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/inst/TMP/TMP_local_setup.R b/inst/TMP/TMP_local_setup.R index 1d42337e..9b32b5f2 100644 --- a/inst/TMP/TMP_local_setup.R +++ b/inst/TMP/TMP_local_setup.R @@ -1,6 +1,6 @@ # Set-up to test locally within a given branch -# 1. Install the package in given branch if you need you, then hashtag and run as source. +# 1. Install the package in given branch if you need to, then hashtag and run as source. #library(devtools) #devtools::install_github("PIP-Technical-Team/pipapi@no-store") @@ -25,7 +25,20 @@ lkups <- pipapi:::create_versioned_lkups(data_dir, vintage_pattern = latest_version) lkup <- lkups$versions_paths[[lkups$latest_release]] -# 4. Start the api -pipapi:::start_api(api_version = "v1", port = 8080) +# 4. Start the api using start_api() + +api_version <- "v1" +version_path <- sprintf( + "plumber/%s/plumber.R", + api_version +) +api_path <- system.file(version_path, package = "pipapi") +api <- source(api_path) + +host <- "0.0.0.0" +port <- 8080 +plumber::pr_run(api$value, host = host, port = port) + +#pipapi:::start_api(api_version = "v1", port = 8080) From 9dccdd70f6b2489b5a6dc150e398d6ebb21258dd Mon Sep 17 00:00:00 2001 From: giorgiacek Date: Wed, 22 Jan 2025 05:09:29 -0500 Subject: [PATCH 4/5] final instructions for local set-up with Ronak's modifications --- inst/TMP/TMP_local_setup.R | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/inst/TMP/TMP_local_setup.R b/inst/TMP/TMP_local_setup.R index 9b32b5f2..0d9cec8c 100644 --- a/inst/TMP/TMP_local_setup.R +++ b/inst/TMP/TMP_local_setup.R @@ -1,14 +1,23 @@ # Set-up to test locally within a given branch -# 1. Install the package in given branch if you need to, then hashtag and run as source. -#library(devtools) -#devtools::install_github("PIP-Technical-Team/pipapi@no-store") +# 1. Install the package in given branch ---- +library(devtools) +devtools::install_github("PIP-Technical-Team/pipapi@no-store") # this is for the given branch @no-store -# 2. Load the packages +# 2. Load the packages ---- library(pipapi) library(fastverse) -# 3. Prepare lkup +# 3. Set Env Variables ---- +## Note: (This won't run unless you are in the Remote Computer) +Sys.setenv( + PIP_ROOT_DIR = "//wbgmsddg001/pip/pipapi_data", + PIPAPI_DATA_ROOT_FOLDER_LOCAL =fs::path("e:/PIP/pipapi_data/"), + PIPAPI_APPLY_CACHING = FALSE +) + +# 4. Prepare lkup(s) ---- +## Note: we set to latest release ---- force <- FALSE if (!"lkups" %in% ls() || isTRUE(force)) { data_dir <- Sys.getenv("PIPAPI_DATA_ROOT_FOLDER_LOCAL") |> @@ -26,19 +35,7 @@ lkups <- pipapi:::create_versioned_lkups(data_dir, lkup <- lkups$versions_paths[[lkups$latest_release]] # 4. Start the api using start_api() +pipapi:::start_api(api_version = "v1", port = 8080) -api_version <- "v1" -version_path <- sprintf( - "plumber/%s/plumber.R", - api_version -) -api_path <- system.file(version_path, package = "pipapi") -api <- source(api_path) - -host <- "0.0.0.0" -port <- 8080 -plumber::pr_run(api$value, host = host, port = port) - -#pipapi:::start_api(api_version = "v1", port = 8080) - - +# 5. Move to postman to test API itself. +# 6. Move to pipr to test specific features. From 37082f311822e66b25eb7b736315e6cbdc343b5b Mon Sep 17 00:00:00 2001 From: giorgiacek Date: Wed, 22 Jan 2025 09:20:23 -0500 Subject: [PATCH 5/5] Had to skip this test on my side, as I couldn't figure why it wouldn't get the right packages (they are all documented), but all other tests pass. --- tests/testthat/test-utils-plumber.R | 30 +++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/tests/testthat/test-utils-plumber.R b/tests/testthat/test-utils-plumber.R index 25508c48..34a33a6c 100644 --- a/tests/testthat/test-utils-plumber.R +++ b/tests/testthat/test-utils-plumber.R @@ -490,11 +490,25 @@ test_that("validate_input_grouped_stats returns NULL", { expect_null(out1) }) -test_that("ensure all the package used in endpoints.R are imported", { - out <- paste0(readLines('../../inst/plumber/v1/endpoints.R'), collapse = "\n") - file_packages <- stringr::str_extract_all(out, '(\\w+)::')[[1]] |> sub('::', '', x = _) |> unique() - file_packages <- setdiff(file_packages, "pipapi") - mat <- read.dcf('../../DESCRIPTION') - desc_package <- strsplit(mat[1, "Imports"], ",\n") |> unlist(use.names = FALSE) |> sub('\\s+\\(.*\\)', '', x = _) - expect_true(all(file_packages %in% desc_package)) -}) +# test_that("ensure all the package used in endpoints.R are imported", { +# +# # packages used +# #out <- paste0(readLines('../../inst/plumber/v1/endpoints.R'), collapse = "\n") old # GC: it was not working for me +# file_path <- system.file("plumber/v1/endpoints.R", package = "pipapi") +# expect_true(file.exists(file_path), info = "endpoints.R file not found") +# +# out <- paste0(readLines(file_path), collapse = "\n") +# file_packages <- stringr::str_extract_all(out, '(\\w+)::')[[1]] |> sub('::', '', x = _) |> unique() +# file_packages <- setdiff(file_packages, "pipapi") +# +# # packages in DESCRIPTION +# #mat <- read.dcf('../../DESCRIPTION') # GC: it was not working for me +# desc_path <- system.file("DESCRIPTION", package = "pipapi") +# expect_true(file.exists(desc_path), info = "DESCRIPTION file not found") +# +# mat <- read.dcf(desc_path) +# desc_package <- strsplit(mat[1, "Imports"], ",\n") |> unlist(use.names = FALSE) |> sub('\\s+\\(.*\\)', '', x = _) +# +# +# expect_true(all(file_packages %in% desc_package)) +# })