Skip to content
This repository was archived by the owner on Oct 12, 2023. It is now read-only.

Commit b4248cf

Browse files
committed
implement retry logic in getjobresult
1 parent 58de322 commit b4248cf

File tree

1 file changed

+50
-8
lines changed

1 file changed

+50
-8
lines changed

R/utility.R

Lines changed: 50 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -387,20 +387,62 @@ getJobResult <- function(jobId) {
387387
if (metadata$enableCloudCombine == "FALSE") {
388388
cat("enalbeCloudCombine is set to FALSE, no job merge result is available",
389389
fill = TRUE)
390+
390391
return()
391392
}
392393

394+
if (metadata$wait == "FALSE") {
395+
job <- getJob(jobId, verbose = FALSE)
396+
397+
if (job$tasks$active != 0 && job$tasks$running != 0) {
398+
stop(sprintf(
399+
"job %s is not finished yet, please try again later",
400+
job$jobId
401+
))
402+
}
403+
404+
# if the job has failed task
405+
if (job$tasks$failed > 0 && metadata$errorHandling == "stop") {
406+
stop(
407+
sprintf(
408+
"job %s has failed tasks and error handling is set to 'stop', no result will be avaialble",
409+
job$jobId
410+
)
411+
)
412+
}
413+
}
414+
393415
tempFile <- tempfile("getJobResult", fileext = ".rds")
394416

395-
results <- rAzureBatch::downloadBlob(
396-
jobId,
397-
paste0("result/", jobId, "-merge-result.rds"),
398-
downloadPath = tempFile,
399-
overwrite = TRUE
400-
)
417+
retryCounter <- 0
418+
maxRetryCount <- 3
419+
repeat {
420+
if (retryCounter > maxRetryCount) {
421+
stop(
422+
sprintf(
423+
"Error getting job result: Maxmium number of retries (%d) reached",
424+
maxRetryCount
425+
)
426+
)
427+
} else {
428+
retryCounter <- retryCounter + 1
429+
}
401430

402-
if (is.vector(results)) {
403-
results <- readRDS(tempFile)
431+
results <- rAzureBatch::downloadBlob(
432+
jobId,
433+
paste0("result/", jobId, "-merge-result.rds"),
434+
downloadPath = tempFile,
435+
overwrite = TRUE
436+
)
437+
438+
if (is.vector(results)) {
439+
results <- readRDS(tempFile)
440+
break
441+
442+
}
443+
444+
# wait for 10 seconds for the result to be available
445+
Sys.sleep(10)
404446
}
405447

406448
return(results)

0 commit comments

Comments
 (0)