-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update the pipeline to include getting data and sending email
- Loading branch information
1 parent
c8777db
commit 0ebe763
Showing
4 changed files
with
50 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
send_email <- function(){ | ||
|
||
|
||
send_email <- function(recipient, email_file){ | ||
#put email sending code here | ||
|
||
print(paste0("Send email content ",email_file," to ",recipient)) | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# This is a script that can be run from command line (e.g. on a schedule) | ||
|
||
#STEP 1 | ||
#getting or generating batch_id | ||
args <- commandArgs(TRUE) # get batch id from command line | ||
if (length(args)>0){ | ||
batch_id <- args[1] | ||
} else { #set a batch id to date + random letters | ||
batch_id <- paste0(Sys.Date(),"-",paste(sample(letters,10),collapse = "")) | ||
} | ||
|
||
config <- config::get() | ||
|
||
# this may need to be set if calling from the recorder feedback controller | ||
#setwd("./R/recorder-feedback-content") | ||
|
||
if(!require(renv)){ | ||
install.packages("renv",repos='http://cran.r-project.org') | ||
library(renv) | ||
} | ||
|
||
#activate the renv environment | ||
source("renv/activate.R") | ||
renv::restore() | ||
|
||
# OPTIONAL: Get data (if using external sources) | ||
source("R/get_users_and_records.R") | ||
|
||
# Set an environment variable in R for the batch code | ||
Sys.setenv(BATCH_ID = batch_id) | ||
|
||
# run the pipeline | ||
targets::tar_make() | ||
|
||
#and unset the variable | ||
Sys.unsetenv("BATCH_ID") | ||
|
||
# OPTIONAL: send the emails | ||
source("R/send_email.R") | ||
meta_table <-read.csv(paste0("renders/",batch_id,"/meta_table_",batch_id,".csv")) | ||
for (i in 1:nrow(meta_table)){ | ||
#get their email address | ||
participants <- read.csv(config$participant_data_file) | ||
recipient <- participants[participants$user_id == meta_table[i,"user_id"],]$email | ||
send_email(recipient,meta_table$file[i]) | ||
} |