Skip to content

Commit

Permalink
fix bug private api_command_execute() now manage well and wait end of…
Browse files Browse the repository at this point in the history
… current task
  • Loading branch information
berthetclement committed Dec 19, 2024
1 parent 9322354 commit daab55f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@
(cf. Antares v9 changelog)

NEW FEATURES (Antares v9.0) :

* `createStudy()` takes into account the new format of Antares studies (e.g. 9.0, 9.15 instead of 900, 915)

BUGFIXES :

* *[private function]* `api_command_execute()` manage snapshot generation of a variant study with a tempo to wait the end of current task (prevents the order from being ignored).



# antaresEditObject 0.7.1
Expand Down
33 changes: 31 additions & 2 deletions R/API-utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,38 @@ api_command_execute <- function(command, opts, text_alert = "{msg_api}") {
msg_api=" " # HACK /!\
cli::cli_alert_success(paste0(text_alert, "success"))

# one more "PUT" "/generate" for variant only
# Snaphost /generate" for variant only
if (is_variant(opts)) {
api_put(opts, paste0(opts$study_id, "/generate"))
variant_res <- api_put(opts, paste0(opts$study_id, "/generate"))

# retrieve task information
result_task_id <- api_get(opts = opts,
endpoint = file.path("v1", "tasks", variant_res),
default_endpoint = NULL)

while(is.null(result_task_id$result)) {
message("...Generate Snapshot task in progress...")
if(is.null(opts$sleep))
Sys.sleep(0.5)
else
Sys.sleep(opts$sleep)
result_task_id <- api_get(opts = opts,
endpoint = file.path("v1", "tasks", variant_res),
default_endpoint = NULL)
}

# test if task is terminated with success
result_task_id_log <- result_task_id$result

status <- isTRUE(result_task_id_log$success)

details_command <- jsonlite::fromJSON(result_task_id_log$return_value,
simplifyVector = FALSE)

if(status)
message(paste0("Snapshot generated for : ", details_command$details[[1]]$name))
else
stop(paste0("Not success for task : ", details_command$details[[1]]$name))
return(invisible(TRUE))
}
}
Expand Down

0 comments on commit daab55f

Please sign in to comment.