Skip to content

Commit

Permalink
wait for task completion
Browse files Browse the repository at this point in the history
  • Loading branch information
jjallaire committed Oct 2, 2013
1 parent 5980434 commit 1b9fd62
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
9 changes: 5 additions & 4 deletions R/deploy.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,17 @@ deploy <- function(appDir = getwd(), appName = NULL, account = NULL) {
# deploy the bundle
task <- lucid$deployApplication(application$id, bundle$id)

# poll for task status

# wait for the deployment to complete (will raise an error if it can't)
lucid$waitForTaskCompletion(task$task_id)

# save a record of the deployment
# save the deployment info for easier updates
saveDeployment(appDir,
target$appName,
target$account,
bundle$id,
application$url)


# successful deployment!
invisible(TRUE)
}

Expand Down
30 changes: 30 additions & 0 deletions R/lucid.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,36 @@ lucidClient <- function(authInfo) {
json <- list()
json$bundle <- as.numeric(bundleId)
handleResponse(POST_JSON(authInfo, path, json))
},

waitForTaskCompletion = function(taskId, displayStatus = TRUE) {

path <- paste("/v1/tasks/", taskId, sep="")

lastStatus <- NULL
while(TRUE) {
# check status
status <- handleResponse(GET(authInfo, path))

# are we finished? (note: this codepath is the only way to exit
# this function)
if (status$finished) {
if (identical(status$status, "complete"))
return (NULL)
else
stop(status$error, call. = FALSE)
}

# display status to the user if it changed
else if (!identical(lastStatus, status$status)) {
if (displayStatus)
cat(status$status, "\n")
lastStatus <- status$status
}

# wait for 1 second before polling again
Sys.sleep(1)
}
}
)
}
Expand Down

0 comments on commit 1b9fd62

Please sign in to comment.