

def wait_on_done(self, interval=2, timeout=((3600 * 24) * 7), **kwargs):
    "\n        :param interval: Number of seconds between queries to the analysis's state\n        :type interval: integer\n        :param timeout: Maximum amount of time to wait, in seconds, until the analysis is done (or at least partially failed)\n        :type timeout: integer\n        :raises: :exc:`~dxpy.exceptions.DXError` if the timeout is reached before the analysis has finished running, or :exc:`~dxpy.exceptions.DXJobFailureError` if some job in the analysis has failed\n\n        Waits until the analysis has finished running.\n        "
    elapsed = 0
    while True:
        state = self._get_state(**kwargs)
        if (state == 'done'):
            break
        if (state in ['failed', 'partially_failed']):
            desc = self.describe(**kwargs)
            err_msg = 'Analysis has failed because of {failureReason}: {failureMessage}'.format(**desc)
            if ((desc.get('failureFrom') != None) and (desc['failureFrom']['id'] != desc['id'])):
                err_msg += ' (failure from {id})'.format(id=desc['failureFrom']['id'])
            raise DXJobFailureError(err_msg)
        if (state == 'terminated'):
            raise DXJobFailureError('Analysis was terminated.')
        if ((elapsed >= timeout) or (elapsed < 0)):
            raise DXJobFailureError('Reached timeout while waiting for the analysis to finish')
        time.sleep(interval)
        elapsed += interval

dataset/ETHPy150Open dnanexus/dx-toolkit/src/python/dxpy/bindings/dxanalysis.py DXAnalysis.wait_on_done/original