def wait_for_job(self, job, interval=5, timeout=60):
        """
        Waits until the job indicated by job_resource is done or has failed

        Parameters
        ----------
        job : Union[dict, str]
            ``dict`` representing a BigQuery job resource, or a ``str``
            representing the BigQuery job id
        interval : float, optional
            Polling interval in seconds, default = 5
        timeout : float, optional
            Timeout in seconds, default = 60

        Returns
        -------
        dict
            Final state of the job resouce, as described here:
            https://developers.google.com/resources/api-libraries/documentation/bigquery/v2/python/latest/bigquery_v2.jobs.html#get

        Raises
        ------
        Union[JobExecutingException, BigQueryTimeoutException]
            On http/auth failures or timeout
        """
        complete = False
        job_id = str(job if isinstance(job,
                                       (six.binary_type, six.text_type, int))
                     else job['jobReference']['jobId'])
        job_resource = None

        start_time = time()
        elapsed_time = 0
        while not (complete or elapsed_time > timeout):
            sleep(interval)
            request = self.bigquery.jobs().get(projectId=self.project_id,
                                               jobId=job_id)
            job_resource = request.execute()
            self._raise_executing_exception_if_error(job_resource)
            complete = job_resource.get('status').get('state') == u'DONE'
            elapsed_time = time() - start_time

        # raise exceptions if timeout
        if not complete:
            logger.error('BigQuery job %s timeout' % job_id)
            raise BigQueryTimeoutException()

        return job_resource
dataset/ETHPy150Open tylertreat/BigQuery-Python/bigquery/client.py/BigQueryClient.wait_for_job/original