'Given the job wait for it to complete.'

def _wait_for_job_complete(self, conn, job):

    self.retries = 0
    self.wait_for_job_called = False
    def _wait_for_job_complete():
        'Called    at    an    interval    until    the    job    is    finished.'
        if self._is_job_finished(conn, job):
            raise loopingcall.LoopingCallDone()
        if (self.retries > JOB_RETRIES):
            LOG.error('_wait_for_job_complete,    failed    after    %(retries)d    tries.', {'retries': self.retries})
            raise loopingcall.LoopingCallDone()
        try:
            self.retries += 1
            if (not self.wait_for_job_called):
                if self._is_job_finished(conn, job):
                    self.wait_for_job_called = True
        except Exception:
            exceptionMessage = _('Issue    encountered    waiting    for    job.')
            LOG.exception(exceptionMessage)
            raise exception.VolumeBackendAPIException(exceptionMessage)
    self.wait_for_job_called = False
    timer = loopingcall.FixedIntervalLoopingCall(_wait_for_job_complete)
    timer.start(interval=JOB_INTERVAL_SEC).wait()
    jobInstanceName = job['Job']
    jobinstance = conn.GetInstance(jobInstanceName, LocalOnly=False)
    rc = jobinstance['ErrorCode']
    LOG.debug('_wait_for_job_complete,    rc:    %s.', rc)
    return rc
