Febian Shah Febian Shah - 1 year ago 104
Java Question

BigQuery job status is always "PENDING"

I'm trying to run the following code, but the status variable is always "PENDING". Could you please tell me what am I doing wrong?

Job execute = bigquery.jobs().insert(PROJECT_ID, runJob).execute();

String status;
while(status.equalsIgnoreCase("PENDING")) {
status = execute.getStatus().getState();
System.out.println("Status: " + status);

Answer Source

Your code isn't making a request to BigQuery to get the updated state, it's just checking the state of the Job returned by the insert call.

Instead, you should poll for the state of the job by issuing a jobs.get request, and check that state, e.g.:

Job job = bigquery.jobs().insert(PROJECT_ID, runJob).execute();
String status = job.getStatus().getState();
while(!status.equalsIgnoreCase("DONE")) {
  status = bigquery.jobs().get(PROJECT_ID, job.getId()).execute().getStatus().getState();
  System.out.println("Status: " + status);

*Edited based on Jordan Tigani's comment.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download