Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception handling and timing for execution #149

Merged
merged 45 commits into from
Aug 9, 2024

Conversation

anthonysena
Copy link
Collaborator

@anthonysena anthonysena commented Jul 16, 2024

Aims to address #141 to provide better exception handling for execution. This work depends on the completion of #145. I've provided a reprex below to show how this is currently working.

A few notes:

  • Making use of purrr::safely works nicely to capture errors and to provide a summary of the entirety of the execution. The only potential downside is that we don't seem to get a stack trace (but this may be due to my contrived example that will eventually be the basis for a test case).
  • I'm not currently emitting the errors when they occur which may make the logs confusing - an alternative may be to use ParallelLogger::logError in the case that an error is encountered during the iteration over all module execution.
  • We may want to control this behavior via a parameter to the execute function such that we may want to stop upon an error.

Reprex

# Create a simple class that throws an error upon execution
ExceptionThrowerModule <- R6::R6Class(
  classname = "ExceptionThrowerModule",
  inherit = Strategus:::StrategusModule,
  public = list(
    #' @description Initialize the module
    initialize = function() {
      super$initialize()
    },
    execute = function(connectionDetails, analysisSpecifications, executionSettings) {
      super$execute(connectionDetails, analysisSpecifications, executionSettings)
      checkmate::assertClass(executionSettings, "CdmExecutionSettings")
      stop("THROWING EXCEPTION")
    }
  )
)

# Create a simple class that prints a message
SimpleModule <- R6::R6Class(
  classname = "SimpleModule",
  inherit = Strategus:::StrategusModule,
  public = list(
    #' @description Initialize the module
    initialize = function() {
      super$initialize()
    },
    execute = function(connectionDetails, analysisSpecifications, executionSettings) {
      super$execute(connectionDetails, analysisSpecifications, executionSettings)
      checkmate::assertClass(executionSettings, "CdmExecutionSettings")
      private$.message("Hello World")
    }
  )
)


# Create a simple analysis spec with this module
etm <- ExceptionThrowerModule$new()
etmSpecs <- etm$createModuleSpecifications(list(foo = "bar"))

sm <- SimpleModule$new()
smSpecs <- sm$createModuleSpecifications(list(foo = "bar"))

analysisSpecifications <- Strategus::createEmptyAnalysisSpecificiations() |>
  Strategus::addModuleSpecifications(smSpecs) |>
  Strategus::addModuleSpecifications(etmSpecs) |>
  Strategus::addModuleSpecifications(smSpecs)

# Execute the study
executionSettings <- Strategus::createCdmExecutionSettings(
  workDatabaseSchema = "main",
  cdmDatabaseSchema = "main",
  cohortTableNames = CohortGenerator::getCohortTableNames(cohortTable = "strategus_test"),
  workFolder = file.path(getwd(), "workFolder"),
  resultsFolder = file.path(getwd(), "resultsFolder"),
  minCellCount = 5
)

connectionDetails <- Eunomia::getEunomiaConnectionDetails()
Strategus::execute(
  analysisSpecifications = analysisSpecifications,
  executionSettings = executionSettings,
  connectionDetails = connectionDetails
)
#> Currently in a tryCatch or withCallingHandlers block, so unable to add global calling handlers. ParallelLogger will not capture R messages, errors, and warnings, only explicit calls to ParallelLogger. (This message will not be shown again this R session)
#> Connecting using SQLite driver
#> EXECUTING: SimpleModule
#> Hello World
#> EXECUTING: ExceptionThrowerModule
#> EXECUTING: SimpleModule
#> Hello World
#> 
#> 
#> -- EXECUTION SUMMARY -----------------------------------------------------------
#> 
#> v SimpleModule
#> 
#> x ExceptionThrowerModule ERROR: THROWING EXCEPTION
#> 
#> v SimpleModule

Created on 2024-07-16 with reprex v2.1.0

# This is the 1st commit message:

Debugging

# This is the commit message #2:

Change CG declaration; remove 4.2.3 specific tests

# This is the commit message #3:

Fix typo

# This is the commit message #4:

Mod linux setup

# This is the commit message #5:

Remove branch identifier for CG
@anthonysena anthonysena linked an issue Jul 16, 2024 that may be closed by this pull request
@anthonysena anthonysena changed the base branch from remove-deps-add-module-interface to v1.0-main July 31, 2024 15:31
@anthonysena anthonysena linked an issue Aug 7, 2024 that may be closed by this pull request
@anthonysena anthonysena changed the title Initial exception handling for execution Exception handling and timing for execution Aug 7, 2024
@anthonysena anthonysena marked this pull request as ready for review August 8, 2024 12:54
@anthonysena anthonysena merged commit 17ffa2c into v1.0-main Aug 9, 2024
8 checks passed
@anthonysena anthonysena deleted the v1.0-exception-handling branch August 9, 2024 17:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Exception handling for modules/packages Keep a record of time needed to execute each module
1 participant