Skip to content

Commit 70b25c2

Browse files
committed
feat: add s3 sync option for targets
1 parent 1c55ae2 commit 70b25c2

File tree

2 files changed

+30
-7
lines changed

2 files changed

+30
-7
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ DEBUG_MODE=true
1616
USE_SHINY=false
1717
TAR_PROJECT=covid_hosp_explore
1818
EXTERNAL_SCORES_PATH=
19+
USE_AWS_S3=false
20+
AWS_S3_PREFIX=
1921

2022
# Run the pipeline wrapper run.R.
2123
make run
@@ -26,6 +28,8 @@ make run
2628
- `USE_SHINY` controls whether we start a Shiny server after producing the targets.
2729
- `TAR_PROJECT` controls which `targets` project is run by `run.R`.
2830
- `EXTERNAL_SCORES_PATH` controls where external scores are loaded from. If not set, external scores are not used.
31+
- `USE_AWS_S3` controls whether we use AWS S3 to store the cache.
32+
- `AWS_S3_PREFIX` controls the prefix for the AWS S3 bucket.
2933

3034
## Development
3135

run.R

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
# # Example fetching external scores from the forecasting bucket
1111
# library(aws.s3)
1212
#
13+
# # We recommend setting these in your user config files such as ~/.zprofile.
1314
# Sys.setenv(
1415
# AWS_ACCESS_KEY_ID = "",
1516
# AWS_SECRET_ACCESS_KEY = ""
@@ -25,17 +26,23 @@
2526
# # Save to disk
2627
# saveRDS(scorecards, "exploration-scorecards-2023-10-04.RDS")
2728

28-
print("Reading environment variables (TAR_PROJECT, EXTERNAL_SCORES_PATH, DEBUG_MODE, USE_SHINY)...")
2929
tar_project <- Sys.getenv("TAR_PROJECT", "covid_hosp_explore")
3030
external_scores_path <- Sys.getenv("EXTERNAL_SCORES_PATH", "")
3131
debug_mode <- as.logical(Sys.getenv("DEBUG_MODE", TRUE))
3232
use_shiny <- as.logical(Sys.getenv("USE_SHINY", FALSE))
33-
34-
cat("Using project: ", tar_project, "\n")
35-
if (external_scores_path != "") cat("Using external scores from ", external_scores_path, "\n")
36-
if (debug_mode) cat("Debug mode is on.")
37-
if (use_shiny) cat("Running shiny server after results.")
38-
33+
use_aws_s3 <- as.logical(Sys.getenv("USE_AWS_S3", FALSE))
34+
aws_s3_prefix <- Sys.getenv("AWS_S3_PREFIX", "exploration")
35+
cli::cli_inform(
36+
c(
37+
"i" = "Reading environment variables...",
38+
"*" = "TAR_PROJECT = {tar_project}",
39+
"*" = "EXTERNAL_SCORES_PATH = {external_scores_path}",
40+
"*" = "DEBUG_MODE = {debug_mode}",
41+
"*" = "USE_SHINY = {use_shiny}",
42+
"*" = "USE_AWS_S3 = {use_aws_s3}",
43+
"*" = "AWS_S3_PREFIX = {aws_s3_prefix}"
44+
)
45+
)
3946

4047
suppressPackageStartupMessages({
4148
library(targets)
@@ -46,6 +53,18 @@ suppressPackageStartupMessages({
4653
store_dir <- tar_path_store()
4754
if (!dir.exists(store_dir)) dir.create(store_dir)
4855

56+
if (use_aws_s3) {
57+
tar_option_set(
58+
repository = "aws",
59+
resources = tar_resources(
60+
aws = tar_resources_aws(
61+
bucket = "forecasting-team-data",
62+
prefix = aws_s3_prefix
63+
)
64+
)
65+
)
66+
}
67+
4968
tar_manifest()
5069
if (debug_mode) {
5170
tar_make(callr_function = NULL)

0 commit comments

Comments
 (0)