/** Example of waiting for a job until it reports that it is done. */ // [TARGET isDone()] public void isDone() throws InterruptedException { // [START ] while (!job.isDone()) { Thread.sleep(1000L); } // [END ] }
@Override void run(BigQuery bigquery, JobInfo job) throws Exception { System.out.println("Creating job"); Job startedJob = bigquery.create(job); while (!startedJob.isDone()) { System.out.println("Waiting for job " + startedJob.getJobId().getJob() + " to complete"); Thread.sleep(1000L); } startedJob = startedJob.reload(); if (startedJob.getStatus().getError() == null) { System.out.println("Job " + startedJob.getJobId().getJob() + " succeeded"); } else { System.out.println("Job " + startedJob.getJobId().getJob() + " failed"); System.out.println("Error: " + startedJob.getStatus().getError()); } } }
@Test public void testIsDone_NotExists() throws Exception { initializeExpectedJob(1); BigQuery.JobOption[] expectedOptions = {BigQuery.JobOption.fields(BigQuery.JobField.STATUS)}; expect(bigquery.getOptions()).andReturn(mockOptions); expect(bigquery.getJob(JOB_INFO.getJobId(), expectedOptions)).andReturn(null); replay(bigquery); initializeJob(); assertTrue(job.isDone()); }
@Test public void testIsDone_True() throws Exception { initializeExpectedJob(2); BigQuery.JobOption[] expectedOptions = {BigQuery.JobOption.fields(BigQuery.JobField.STATUS)}; JobStatus status = createStrictMock(JobStatus.class); expect(status.getState()).andReturn(JobStatus.State.DONE); expect(bigquery.getOptions()).andReturn(mockOptions); expect(bigquery.getJob(JOB_INFO.getJobId(), expectedOptions)) .andReturn(expectedJob.toBuilder().setStatus(status).build()); replay(status, bigquery); initializeJob(); assertTrue(job.isDone()); verify(status); }
@Test public void testIsDone_False() throws Exception { initializeExpectedJob(2); BigQuery.JobOption[] expectedOptions = {BigQuery.JobOption.fields(BigQuery.JobField.STATUS)}; JobStatus status = createStrictMock(JobStatus.class); expect(status.getState()).andReturn(JobStatus.State.RUNNING); expect(bigquery.getOptions()).andReturn(mockOptions); expect(bigquery.getJob(JOB_INFO.getJobId(), expectedOptions)) .andReturn(expectedJob.toBuilder().setStatus(status).build()); replay(status, bigquery); initializeJob(); assertFalse(job.isDone()); verify(status); }
if (job.isDone()) { logger.trace("Job is marked done: id={}, status={}", job.getJobId(), job.getStatus()); List<BlobId> blobIdsToDelete = jobEntry.getValue();
@Override public JobInfo job(JobInfo jobInfo, JobOption... options) { Job job = client.create(jobInfo, options); while (!job.isDone()) { try { Thread.sleep(1000); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new RuntimeException(e); } job = job.reload(); } final BigQueryError error = job.getStatus().getError(); if (error != null) { throw new BigQueryException(0, "BigQuery job failed: " + error); } return job; }
if (myJob.isDone())
Clock clock = options.clock(); long startTime = clock.millis(); while (!isDone()) { if (timeoutMillis != -1 && (clock.millis() - startTime) >= timeoutMillis) { throw new TimeoutException();