Skip to content

Commit

Permalink
Merge pull request #15 from MarkEdmondson1234/master
Browse files Browse the repository at this point in the history
add bqr_wait_for_job
  • Loading branch information
MarkEdmondson1234 authored Jun 23, 2016
2 parents dfc0e15 + 84de79d commit b7cd4db
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 5 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ export(bqr_query_asynch)
export(bqr_table_data)
export(bqr_table_meta)
export(bqr_upload_data)
export(bqr_wait_for_job)
import(googleCloudStorageR)
40 changes: 40 additions & 0 deletions R/jobs.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,43 @@
#' Wait for a bigQuery job
#'
#' Wait for a bigQuery job to finish.
#'
#' @param jobObject A job object
#' @param wait The number of seconds to wait between checks
#'
#' Use this function to do a loop to check progress of a job running
#'
#' @return After a while, a completed job
#'
#' @family BigQuery asynch query functions
#' @export
bqr_wait_for_job <- function(job, wait=5){

stopifnot(job$kind == "bigquery#job")

status <- FALSE
time <- Sys.time()

while(!status){
Sys.sleep(wait)
message("Waiting for BigQuery...job timer: ", format(difftime(Sys.time(),
time),
format = "%H:%M:%S"))

job <- bigQueryR::bqr_get_job(projectId = job$jobReference$projectId,
jobId = job$jobReference$jobId)

if(job$status$state == "DONE"){
status <- TRUE
} else {
status <- FALSE
}
}

job
}


#' Poll a jobId
#'
#' @param projectId projectId of job
Expand Down
3 changes: 2 additions & 1 deletion man/bqr_download_extract.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion man/bqr_extract_data.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion man/bqr_get_job.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion man/bqr_grant_extract_access.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion man/bqr_query_asynch.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions man/bqr_wait_for_job.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b7cd4db

Please sign in to comment.