示例#1
0
def get_lock_if_job_is_runnable(app_name, job_id):
    """Return a lock instance or False.  If returning False,
    the job is not ready to execute.
    """

    available = qb.check_state(app_name,
                               job_id,
                               pending=True,
                               raise_if_not_exists=True)
    if not available:
        try:
            raise RuntimeError(
                "I found a job in queue that wasn't"
                " in state pending. This might be a code bug. You"
                " probably queued 2+ of the same job!")
        except RuntimeError as err:
            # force a traceback in the logs
            log.exception(err,
                          extra=dict(app_name=app_name,
                                     job_id=job_id,
                                     state=qb.check_state(app_name,
                                                          job_id,
                                                          _get=True)))
            return False
    l = qb.obtain_execute_lock(app_name, job_id, blocking=False)
    if l is False:
        log.warn(
            'Could not obtain execute lock for task because'
            ' something is already processing this job_id',
            extra=dict(app_name=app_name, job_id=job_id))
        return False
    return l
示例#2
0
文件: runner.py 项目: kszucs/stolos
def get_lock_if_job_is_runnable(app_name, job_id):
    """Return a lock instance or False.  If returning False,
    the job is not ready to execute.
    """

    available = qb.check_state(
        app_name, job_id, pending=True, raise_if_not_exists=True)
    if not available:
        try:
            raise RuntimeError(
                "I found a job in queue that wasn't"
                " in state pending. This might be a code bug. You"
                " probably queued 2+ of the same job!")
        except RuntimeError as err:
            # force a traceback in the logs
            log.exception(
                err, extra=dict(
                    app_name=app_name,
                    job_id=job_id,
                    state=qb.check_state(
                        app_name, job_id, _get=True)))
            return False
    l = qb.obtain_execute_lock(app_name, job_id, blocking=False)
    if l is False:
        log.warn('Could not obtain execute lock for task because'
                 ' something is already processing this job_id',
                 extra=dict(app_name=app_name, job_id=job_id))
        return False
    return l
示例#3
0
def test_rerun_push_tasks1(app1, app2, job_id1):
    # this tests recursively deleteing parent status on child nodes

    # queue and complete app 1. it queues a child
    enqueue(app1, job_id1)
    qb.set_state(app1, job_id1, completed=True)
    consume_queue(app1)
    validate_one_completed_task(app1, job_id1)
    validate_one_queued_task(app2, job_id1)

    # complete app 2
    qb.set_state(app2, job_id1, completed=True)
    consume_queue(app2)
    validate_one_completed_task(app1, job_id1)
    validate_one_completed_task(app2, job_id1)

    # readd app 1
    qb.readd_subtask(app1, job_id1)
    validate_one_queued_task(app1, job_id1)
    validate_zero_queued_task(app2)
    nose.tools.assert_true(
        qb.check_state(app2, job_id1, pending=True))

    # complete app 1
    qb.set_state(app1, job_id1, completed=True)
    consume_queue(app1)
    validate_one_completed_task(app1, job_id1)
    validate_one_queued_task(app2, job_id1)
    # complete app 2
    qb.set_state(app2, job_id1, completed=True)
    consume_queue(app2)
    validate_one_completed_task(app1, job_id1)
    validate_one_completed_task(app2, job_id1)