def test_invalid_queued_job_id(app4, depends_on_job_id1, log, tasks_json_tmpfile): job_id = depends_on_job_id1 # this job_id does not match the app # manually bypass the decorator that validates job_id qb._set_state_unsafe(app4, job_id, pending=True) q = qb.get_qbclient().LockingQueue(app4) q.put(job_id) validate_one_queued_task(app4, job_id) run_code(log, tasks_json_tmpfile, app4, '--bash_cmd echo 123') validate_one_failed_task(app4, job_id) validate_zero_queued_task(app4)
def validate_job_id(app_name, job_id, q, timeout): """Return True if valid job_id. If invalid, do whatever cleanup for this job is necessary and return False. --> necessary cleanup may include removing this job_id from queue """ if job_id is None: log.info('No jobs found in %d seconds...' % timeout, extra=dict(app_name=app_name)) return False try: dt.parse_job_id(app_name, job_id) except exceptions.InvalidJobId as err: log.error( ("Stolos found an invalid job_id. Removing it from queue" " and marking that job_id as failed. Error details: %s") % err, extra=dict(app_name=app_name, job_id=job_id)) q.consume() qb._set_state_unsafe(app_name, job_id, failed=True) return False return True
def validate_job_id(app_name, job_id, q, timeout): """Return True if valid job_id. If invalid, do whatever cleanup for this job is necessary and return False. --> necessary cleanup may include removing this job_id from queue """ if job_id is None: log.info('No jobs found in %d seconds...' % timeout, extra=dict( app_name=app_name)) return False try: dt.parse_job_id(app_name, job_id) except exceptions.InvalidJobId as err: log.error(( "Stolos found an invalid job_id. Removing it from queue" " and marking that job_id as failed. Error details: %s") % err, extra=dict(app_name=app_name, job_id=job_id)) q.consume() qb._set_state_unsafe( app_name, job_id, failed=True) return False return True