def get_qb_status(app_name, job_id): path = qb.get_job_path(app_name, job_id) elockpath = qb.get_lock_path('execute', app_name, job_id) alockpath = qb.get_lock_path('add', app_name, job_id) qbcli = api.get_qbclient() return { 'is_add_locked': qbcli.Lock(alockpath).is_locked(), 'is_execute_locked': qbcli.Lock(elockpath).is_locked(), 'in_queue': qbcli.LockingQueue(app_name).is_queued(job_id), 'app_qsize': qbcli.LockingQueue(app_name).size(), 'state': qbcli.get(path), }
def test_check_state1(app1, job_id1, job_id2): nt.assert_false(api.check_state(app1, 'doesnotexist', pending=True)) with nt.assert_raises(NoNodeError): api.check_state(app1, 'doesnotexist', raise_if_not_exists=True) qb.set_state(app1, job_id1, pending=True) # also: create an invalid state (one that stolos does not recognize) api.get_qbclient().create(qb.get_job_path(app1, job_id2), '') with nt.assert_raises(UserWarning): api.check_state(app1, job_id1) nt.assert_true(api.check_state(app1, job_id1, pending=True)) nt.assert_true(api.check_state(app1, job_id1, pending=True, completed=True)) nt.assert_false(api.check_state(app1, job_id1, completed=True)) nt.assert_true(api.check_state(app1, job_id1, all=True)) # the invalid job: nt.assert_false(api.check_state(app1, job_id2, all=True))
def _handle_manually_given_job_id(ns): """This process was given a specific --job_id arg. Decide whether it's okay to execute this job_id, and if its okay to go forward, set job_id state appropriately """ log.warn( ('using specific job_id and' ' blindly assuming this job is not already queued.'), extra=dict(app_name=ns.app_name, job_id=ns.job_id)) if qb.get_qbclient().exists(qb.get_job_path(ns.app_name, ns.job_id)): msg = ('Will not execute this task because it might be already' ' queued or completed!') log.critical( msg, extra=dict(app_name=ns.app_name, job_id=ns.job_id)) raise UserWarning(msg) lock = qb.obtain_execute_lock( ns.app_name, ns.job_id, safe=False, raise_on_error=True, blocking=False) qb.set_state(ns.app_name, ns.job_id, pending=True) return lock
def _handle_manually_given_job_id(ns): """This process was given a specific --job_id arg. Decide whether it's okay to execute this job_id, and if its okay to go forward, set job_id state appropriately """ log.warn(('using specific job_id and' ' blindly assuming this job is not already queued.'), extra=dict(app_name=ns.app_name, job_id=ns.job_id)) if qb.get_qbclient().exists(qb.get_job_path(ns.app_name, ns.job_id)): msg = ('Will not execute this task because it might be already' ' queued or completed!') log.critical(msg, extra=dict(app_name=ns.app_name, job_id=ns.job_id)) raise UserWarning(msg) lock = qb.obtain_execute_lock(ns.app_name, ns.job_id, safe=False, raise_on_error=True, blocking=False) qb.set_state(ns.app_name, ns.job_id, pending=True) return lock
def test_check_state1(app1, job_id1, job_id2): nt.assert_false(api.check_state(app1, 'doesnotexist', pending=True)) with nt.assert_raises(NoNodeError): api.check_state(app1, 'doesnotexist', raise_if_not_exists=True) qb.set_state(app1, job_id1, pending=True) # also: create an invalid state (one that stolos does not recognize) api.get_qbclient().create( qb.get_job_path(app1, job_id2), '') with nt.assert_raises(UserWarning): api.check_state(app1, job_id1) nt.assert_true( api.check_state(app1, job_id1, pending=True)) nt.assert_true( api.check_state(app1, job_id1, pending=True, completed=True)) nt.assert_false(api.check_state(app1, job_id1, completed=True)) nt.assert_true(api.check_state(app1, job_id1, all=True)) # the invalid job: nt.assert_false(api.check_state(app1, job_id2, all=True))
def validate_not_exists(app_name, job_id): qbcli = api.get_qbclient() path = qb.get_job_path(app_name, job_id) nt.assert_false(qbcli.exists(path))