'Waits for a job to finish
:param entity: The job to wait for'

def _wait_for_job(self, entity):

    running = False
    if (entity.status == 'RUNNING'):
        self.result['changed'] = True
        running = True
    while running:
        time.sleep(1)
        entity.fetch()
        if (entity.status != 'RUNNING'):
            running = False
    self.result['entities'].append(entity.to_dict())
    if (entity.status == 'ERROR'):
        self.module.fail_json(msg='Job    ended    in    an    error')
