diff --git a/NEWS.md b/NEWS.md index c073378..7d385e6 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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 diff --git a/R/API-utils.R b/R/API-utils.R index 1176a5e..1cb8bb8 100644 --- a/R/API-utils.R +++ b/R/API-utils.R @@ -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)) } }