Skip to content

Commit

Permalink
runSimulation: API OK
Browse files Browse the repository at this point in the history
  • Loading branch information
pvictor committed Jun 7, 2022
1 parent b7ce1b3 commit 3a944be
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 11 deletions.
11 changes: 10 additions & 1 deletion R/API.R
Original file line number Diff line number Diff line change
Expand Up @@ -231,13 +231,22 @@ getJobs <- function(opts = antaresRead::simOptions()) {
#' @examples
#' \dontrun{
#'
#' getJobLogs("37afff54-3a8b-40fa-8841-e1dae8854f5f")
#' antaresRead::setSimulationPathAPI(
#' host = "http://localhost:8080",
#' study_id = "39c604fc-687f-46c4-9fa6-59b57ff9c8d1",
#' token = NULL,
#' simulation = "input"
#' )
#' job <- runSimulation()
#' getJobLogs(job)
#'
#' }
getJobLogs <- function(job_id, opts = antaresRead::simOptions()) {
assertthat::assert_that(inherits(opts, "simOptions"))
if (!is_api_study(opts))
stop("getJobLogs can only be used with Antares API.", call. = FALSE)
if (is.list(job_id) && !is.null(job_id$job_id))
job_id <- job_id$job_id
logs <- api_get(opts = opts, paste0("launcher/jobs/", job_id, "/logs"), default_endpoint = "v1")
class(logs) <- c(class(logs), "antares.api.logs")
return(logs)
Expand Down
21 changes: 18 additions & 3 deletions R/runSimulation.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#' @title Run an Antares Simulation
#'
#' @description Run an ANTARES study
#' @description
#' `r antaresEditObject::badge_api_ok()`
#'
#' Run an ANTARES study
#'
#'
#' @param name
#' Name of the simulation.
Expand All @@ -23,8 +27,10 @@
#' [antaresRead::setSimulationPath()]
#'
#' @return
#' The function does not return anything. It is used to launch an
#' ANTARES simulation
#' In API mode it return a `list` with either the job id in case of success of
#' the command or details about the error produce.
#' In non-API mode the function does not return anything, it is used to launch an
#' ANTARES simulation.
#'
#' @importFrom assertthat assert_that
#' @importFrom antaresRead simOptions
Expand All @@ -38,6 +44,15 @@ runSimulation <- function(name,
show_output_on_console = FALSE,
parallel = TRUE,
opts = antaresRead::simOptions()) {
assertthat::assert_that(inherits(opts, "simOptions"))

if (is_api_study(opts)) {

run <- api_post(opts = opts, url = paste0("launcher/run/", opts$study_id), default_endpoint = "v1")
return(run)

}

if (is.null(path_solver)) {
path_solver <- setSolverPath()
}
Expand Down
8 changes: 4 additions & 4 deletions inst/API/dev-api-online.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ library(antaresEditObject)
# Path to our study
opts <- antaresRead::setSimulationPathAPI(
host = "http://localhost:8080",
study_id = "0b26b7e9-57d3-47cb-82c6-d118427eaf7d",
study_id = "39c604fc-687f-46c4-9fa6-59b57ff9c8d1",
token = NULL,
simulation = "input"
)
# temp (implemented in dev version of antaresRead)
opts$host <- "http://localhost:8080"
opts$study_id <- "0b26b7e9-57d3-47cb-82c6-d118427eaf7d"
options(antares = opts)
# opts$host <- "http://localhost:8080"
# opts$study_id <- "0b26b7e9-57d3-47cb-82c6-d118427eaf7d"
# options(antares = opts)



Expand Down
9 changes: 8 additions & 1 deletion man/getJobLogs.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions man/runSimulation.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3a944be

Please sign in to comment.