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

Commit

Permalink
fix subscription out of bounds error (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
zfengms authored Jul 27, 2017
1 parent d8bcd6f commit c913904
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 38 deletions.
50 changes: 27 additions & 23 deletions R/doAzureParallel.R
Original file line number Diff line number Diff line change
Expand Up @@ -290,20 +290,22 @@ setVerbose <- function(value = FALSE){
endIndices[length(startIndices)] <- ntasks
}

tasks <- lapply(1:length(endIndices), function(i){
startIndex <- startIndices[i]
endIndex <- endIndices[i]
taskId <- paste0(id, "-task", i)

.addTask(id,
taskId = taskId,
rCommand = sprintf("Rscript --vanilla --verbose $AZ_BATCH_JOB_PREP_WORKING_DIR/worker.R %s %s %s %s > %s.txt", "$AZ_BATCH_JOB_PREP_WORKING_DIR", "$AZ_BATCH_TASK_WORKING_DIR", jobFileName, paste0(taskId, ".rds"), taskId),
args = argsList[startIndex:endIndex],
envir = .doAzureBatchGlobals,
packages = obj$packages)

return(taskId)
})
if(length(endIndices) > 0){
tasks <- lapply(1:length(endIndices), function(i){
startIndex <- startIndices[i]
endIndex <- endIndices[i]
taskId <- paste0(id, "-task", i)

.addTask(id,
taskId = taskId,
rCommand = sprintf("Rscript --vanilla --verbose $AZ_BATCH_JOB_PREP_WORKING_DIR/worker.R %s %s %s %s > %s.txt", "$AZ_BATCH_JOB_PREP_WORKING_DIR", "$AZ_BATCH_TASK_WORKING_DIR", jobFileName, paste0(taskId, ".rds"), taskId),
args = argsList[startIndex:endIndex],
envir = .doAzureBatchGlobals,
packages = obj$packages)

return(taskId)
})
}

updateJob(id)

Expand Down Expand Up @@ -386,18 +388,20 @@ setVerbose <- function(value = FALSE){
azureStorageUrl <- paste0("http://", storageCredentials$name,".blob.core.windows.net/", id)

staticHtml <- "<h1>Errors:</h1>"
for(i in 1:length(failTasks)){
if(failTasks[i] == 1){
if(length(failTasks) > 0){
for(i in 1:length(failTasks)){
if(failTasks[i] == 1){

stdoutFile <- paste0(azureStorageUrl, "/stdout")
stderrFile <- paste0(azureStorageUrl, "/stderr")
RstderrFile <- paste0(azureStorageUrl, "/logs")
stdoutFile <- paste0(azureStorageUrl, "/stdout")
stderrFile <- paste0(azureStorageUrl, "/stderr")
RstderrFile <- paste0(azureStorageUrl, "/logs")

stdoutFile <- paste0(stdoutFile, "/", id, "-task", i, "-stdout.txt", queryParameterUrl)
stderrFile <- paste0(stderrFile, "/", id, "-task", i, "-stderr.txt", queryParameterUrl)
RstderrFile <- paste0(RstderrFile, "/", id, "-task", i, ".txt", queryParameterUrl)
stdoutFile <- paste0(stdoutFile, "/", id, "-task", i, "-stdout.txt", queryParameterUrl)
stderrFile <- paste0(stderrFile, "/", id, "-task", i, "-stderr.txt", queryParameterUrl)
RstderrFile <- paste0(RstderrFile, "/", id, "-task", i, ".txt", queryParameterUrl)

staticHtml <- paste0(staticHtml, 'Task ', i, ' | <a href="', stdoutFile,'">', "stdout.txt",'</a> |', ' <a href="', stderrFile,'">', "stderr.txt",'</a> | <a href="', RstderrFile,'">', "R output",'</a> <br/>')
staticHtml <- paste0(staticHtml, 'Task ', i, ' | <a href="', stdoutFile,'">', "stdout.txt",'</a> |', ' <a href="', stderrFile,'">', "stderr.txt",'</a> | <a href="', RstderrFile,'">', "R output",'</a> <br/>')
}
}
}

Expand Down
34 changes: 19 additions & 15 deletions R/utility.R
Original file line number Diff line number Diff line change
Expand Up @@ -55,23 +55,27 @@ getJobList <- function(jobIds = c()){
jobs <- listJobs(query = list("$filter" = filter, "$select" = "id,state"))
print("Job List: ")

for(j in 1:length(jobs$value)){
tasks <- listTask(jobs$value[[j]]$id)
count <- 0
if(length(tasks$value) > 0){
taskStates <- lapply(tasks$value, function(x) x$state == "completed")

for(i in 1:length(taskStates)){
if(taskStates[[i]] == TRUE){
count <- count + 1
if(length(jobs$value) > 0){
for(j in 1:length(jobs$value)){
tasks <- listTask(jobs$value[[j]]$id)
count <- 0
if(length(tasks$value) > 0){
taskStates <- lapply(tasks$value, function(x) x$state == "completed")

if(length(taskStates) > 0){
for(i in 1:length(taskStates)){
if(taskStates[[i]] == TRUE){
count <- count + 1
}
}
}
}

summary <- sprintf("[ id: %s, state: %s, status: %d", jobs$value[[j]]$id, jobs$value[[j]]$state, ceiling((count/length(tasks$value) * 100)))
print(paste0(summary, "% ]"))
}
else {
print(sprintf("[ id: %s, state: %s, status: %s ]", jobs$value[[j]]$id, jobs$value[[j]]$state, "No tasks were run."))
summary <- sprintf("[ id: %s, state: %s, status: %d", jobs$value[[j]]$id, jobs$value[[j]]$state, ceiling((count/length(tasks$value) * 100)))
print(paste0(summary, "% ]"))
}
else {
print(sprintf("[ id: %s, state: %s, status: %s ]", jobs$value[[j]]$id, jobs$value[[j]]$state, "No tasks were run."))
}
}
}
}
Expand Down

0 comments on commit c913904

Please sign in to comment.