Skip to content

Commit

Permalink
Update the pipeline to include getting data and sending email
Browse files Browse the repository at this point in the history
  • Loading branch information
simonrolph committed Sep 23, 2024
1 parent c8777db commit 0ebe763
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 28 deletions.
3 changes: 1 addition & 2 deletions R/get_users_and_records.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
library(httr)
library(jsonlite)
library(config)
library(curl)

config <- config::get()
Expand Down Expand Up @@ -51,4 +50,4 @@ for (i in 1:nrow(subscribers_df)){
records_data

#save the data
write.csv(subscribers_df,config$data_file,row.names = F)
write.csv(records_data,config$data_file,row.names = F)
6 changes: 3 additions & 3 deletions R/send_email.R
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))
}
23 changes: 0 additions & 23 deletions generate_feedback_items.R

This file was deleted.

46 changes: 46 additions & 0 deletions run_pipeline.R
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])
}

0 comments on commit 0ebe763

Please sign in to comment.