Skip to content

Commit

Permalink
Remove local library attachment in module run script
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonysena committed Dec 14, 2023
1 parent 00d0c00 commit ed310f2
Show file tree
Hide file tree
Showing 5 changed files with 666 additions and 1,123 deletions.
18 changes: 3 additions & 15 deletions R/ModuleEnv.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,13 @@
#' @param injectVars list of var names list(name=value) to replace (e.g. replace list(foo = "some string") will
#' find the pattern foo and replace it with the string some string - be careful!
#' @param tempScriptFile tempFile to write script to
#' @param useLocalStrategusLibrary Use the locally installed Strategus library? TRUE will use the Strategus
#' installation from the calling R process.
#' @param job run as rstudio job
#' @param processName String name for process
#' @returns NULL invisibly
withModuleRenv <- function(code,
moduleFolder,
injectVars = list(),
tempScriptFile = tempfile(fileext = ".R"),
useLocalStrategusLibrary = TRUE,
job = FALSE,
processName = paste(moduleFolder, "_renv_run")) {
# convert human readable code to a string for writing
Expand All @@ -81,18 +78,9 @@ withModuleRenv <- function(code,
}
}

# Enforce attachment of Strategus from calling process - note one inside the renv
if (useLocalStrategusLibrary) {
script <- c(.getLocalLibraryScipt("Strategus"), script)
# Adding Strategus dependencies to the script
script <- c(.getLocalLibraryScipt("ParallelLogger"), script)
script <- c(.getLocalLibraryScipt("CohortGenerator"), script)
script <- c(.getLocalLibraryScipt("DatabaseConnector"), script)
script <- c(.getLocalLibraryScipt("keyring"), script)
script <- c(.getLocalLibraryScipt("openssl"), script)
script <- c(.getLocalLibraryScipt("dplyr"), script)
script <- c(.getLocalLibraryScipt("R6"), script)
}
# Import the Strategus function we need to retrieve the
# connection details and embed it into the module script
script <- c("retrieveConnectionDetails <- ", base::deparse(Strategus::retrieveConnectionDetails), script)

# Write file and execute script inside an renv
fileConn <- file(tempScriptFile)
Expand Down
4 changes: 2 additions & 2 deletions R/RunModule.R
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,13 @@ runModule <- function(analysisSpecifications, keyringSettings, moduleIndex, exec

# NOTE injected variable isResultsExecution - will look strange outside of Strategus definition
if (isCdmExecution) {
connectionDetails <- Strategus::retrieveConnectionDetails(
connectionDetails <- retrieveConnectionDetails(
connectionDetailsReference = jobContext$moduleExecutionSettings$connectionDetailsReference,
keyringName = keyringName
)
jobContext$moduleExecutionSettings$connectionDetails <- connectionDetails
} else {
resultsConnectionDetails <- Strategus::retrieveConnectionDetails(
resultsConnectionDetails <- retrieveConnectionDetails(
connectionDetailsReference = jobContext$moduleExecutionSettings$resultsConnectionDetailsReference,
keyringName = keyringName
)
Expand Down
Loading

0 comments on commit ed310f2

Please sign in to comment.