'Compute job destination and verify job is ready at that
destination by checking job limits and quota. If this method
return a job state of JOB_READY - it MUST also return a job
destination.'

def __verify_job_ready(self, job, job_wrapper):

    job_destination = None
    try:
        assert (job_wrapper.tool is not None), 'This    tool    was    disabled    before    the    job    completed.        Please    contact    your    Galaxy    administrator.'
        job_destination = job_wrapper.job_destination
    except AssertionError as e:
        log.warning(("(%s)    Tool    '%s'    removed    from    tool    config,    unable    to    run    job" % (job.id, job.tool_id)))
        job_wrapper.fail(e)
        return (JOB_ERROR, job_destination)
    except JobNotReadyException as e:
        job_state = (e.job_state or JOB_WAIT)
        return (job_state, None)
    except Exception as e:
        failure_message = getattr(e, 'failure_message', DEFAULT_JOB_PUT_FAILURE_MESSAGE)
        if (failure_message == DEFAULT_JOB_PUT_FAILURE_MESSAGE):
            log.exception('Failed    to    generate    job    destination')
        else:
            log.debug(('Intentionally    failing    job    with    message    (%s)' % failure_message))
        job_wrapper.fail(failure_message)
        return (JOB_ERROR, job_destination)
    state = self.__check_destination_jobs(job, job_wrapper)
    if (state == JOB_READY):
        state = self.__check_user_jobs(job, job_wrapper)
    if ((state == JOB_READY) and self.app.config.enable_quotas):
        quota = self.app.quota_agent.get_quota(job.user)
        if (quota is not None):
            try:
                usage = self.app.quota_agent.get_usage(user=job.user, history=job.history)
                if (usage > quota):
                    return (JOB_USER_OVER_QUOTA, job_destination)
            except AssertionError as e:
                pass
    if ((state == JOB_READY) and ('delta' in self.app.job_config.limits.total_walltime)):
        jobs_to_check = self.sa_session.query(model.Job).filter((model.Job.user_id == job.user.id), (model.Job.update_time >= (datetime.datetime.now() - datetime.timedelta(self.app.job_config.limits.total_walltime['window']))), (model.Job.state == 'ok')).all()
        time_spent = datetime.timedelta(0)
        for job in jobs_to_check:
            started = None
            finished = None
            for history in sorted(job.state_history, key=(lambda history: history.update_time)):
                if (history.state == 'running'):
                    started = history.create_time
                elif (history.state == 'ok'):
                    finished = history.create_time
            time_spent += (finished - started)
        if (time_spent > self.app.job_config.limits.total_walltime['delta']):
            return (JOB_USER_OVER_TOTAL_WALLTIME, job_destination)
    return (state, job_destination)
