Skip to content

Commit eaf833a

Browse files
fix bug private api_command_execute() now manage well and wait end of current task (#194)
1 parent c6c4640 commit eaf833a

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

NEWS.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ GITHUB ACTIONS :
1414
* test-coverage.yaml updated
1515

1616

17+
BUGFIXES :
18+
19+
* *[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).
20+
21+
1722

1823
# antaresEditObject 0.7.1
1924

R/API-utils.R

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,38 @@ api_command_execute <- function(command, opts, text_alert = "{msg_api}") {
200200
msg_api=" " # HACK /!\
201201
cli::cli_alert_success(paste0(text_alert, "success"))
202202

203-
# one more "PUT" "/generate" for variant only
203+
# Snaphost /generate" for variant only
204204
if (is_variant(opts)) {
205-
api_put(opts, paste0(opts$study_id, "/generate"))
205+
variant_res <- api_put(opts, paste0(opts$study_id, "/generate"))
206+
207+
# retrieve task information
208+
result_task_id <- api_get(opts = opts,
209+
endpoint = file.path("v1", "tasks", variant_res),
210+
default_endpoint = NULL)
211+
212+
while(is.null(result_task_id$result)) {
213+
message("...Generate Snapshot task in progress...")
214+
if(is.null(opts$sleep))
215+
Sys.sleep(0.5)
216+
else
217+
Sys.sleep(opts$sleep)
218+
result_task_id <- api_get(opts = opts,
219+
endpoint = file.path("v1", "tasks", variant_res),
220+
default_endpoint = NULL)
221+
}
222+
223+
# test if task is terminated with success
224+
result_task_id_log <- result_task_id$result
225+
226+
status <- isTRUE(result_task_id_log$success)
227+
228+
details_command <- jsonlite::fromJSON(result_task_id_log$return_value,
229+
simplifyVector = FALSE)
230+
231+
if(status)
232+
message(paste0("Snapshot generated for : ", details_command$details[[1]]$name))
233+
else
234+
stop(paste0("Not success for task : ", details_command$details[[1]]$name))
206235
return(invisible(TRUE))
207236
}
208237
}

0 commit comments

Comments
 (0)