本文整理汇总了Python中aiorq.Queue类的典型用法代码示例。如果您正苦于以下问题:Python Queue类的具体用法?Python Queue怎么用?Python Queue使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Queue类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_worker_sets_job_status
def test_worker_sets_job_status(loop):
"""Ensure that worker correctly sets job status."""
q = Queue()
w = Worker([q])
job = yield from q.enqueue(say_hello)
assert (yield from job.get_status()) == JobStatus.QUEUED
assert (yield from job.is_queued)
assert not (yield from job.is_finished)
assert not (yield from job.is_failed)
yield from w.work(burst=True, loop=loop)
job = yield from Job.fetch(job.id)
assert (yield from job.get_status()) == JobStatus.FINISHED
assert not (yield from job.is_queued)
assert (yield from job.is_finished)
assert not (yield from job.is_failed)
# Failed jobs should set status to "failed"
job = yield from q.enqueue(div_by_zero, args=(1,))
yield from w.work(burst=True, loop=loop)
job = yield from Job.fetch(job.id)
assert (yield from job.get_status()) == JobStatus.FAILED
assert not (yield from job.is_queued)
assert not (yield from job.is_finished)
assert (yield from job.is_failed)
示例2: test_create_job_with_ttl_should_expire
def test_create_job_with_ttl_should_expire(redis):
"""A job created with ttl expires."""
queue = Queue(connection=redis)
queue.enqueue(say_hello, job_id="1234", ttl=1)
time.sleep(1)
assert not len((yield from queue.get_jobs()))
示例3: test_work_fails
def test_work_fails(loop):
"""Failing jobs are put on the failed queue."""
q = Queue()
failed_q = get_failed_queue()
# Preconditions
assert not (yield from failed_q.count)
assert not (yield from q.count)
# Action
job = yield from q.enqueue(div_by_zero)
assert (yield from q.count) == 1
# keep for later
enqueued_at_date = strip_microseconds(job.enqueued_at)
w = Worker([q])
yield from w.work(burst=True, loop=loop) # Should silently pass
# Postconditions
assert not (yield from q.count)
assert (yield from failed_q.count) == 1
assert not (yield from w.get_current_job_id())
# Check the job
job = yield from Job.fetch(job.id)
assert job.origin == q.name
# Should be the original enqueued_at date, not the date of enqueueing
# to the failed queue
assert job.enqueued_at == enqueued_at_date
assert job.exc_info # should contain exc_info
示例4: test_create_job_with_ttl_should_have_ttl_after_enqueued
def test_create_job_with_ttl_should_have_ttl_after_enqueued(redis):
"""Create jobs with ttl and checks if get_jobs returns it properly."""
queue = Queue(connection=redis)
yield from queue.enqueue(say_hello, job_id="1234", ttl=10)
job = (yield from queue.get_jobs())[0]
assert job.ttl == 10
示例5: test_queue_is_empty
def test_queue_is_empty(redis):
"""Detecting empty queues."""
q = Queue('example')
assert (yield from q.is_empty())
yield from redis.rpush('rq:queue:example', 'sentinel message')
assert not (yield from q.is_empty())
示例6: test_ttl_via_enqueue
def test_ttl_via_enqueue(redis):
"""Enqueue set custom TTL on job."""
ttl = 1
queue = Queue(connection=redis)
job = yield from queue.enqueue(say_hello, ttl=ttl)
assert job.get_ttl() == ttl
示例7: test_work_is_unreadable
def test_work_is_unreadable(redis, loop):
"""Unreadable jobs are put on the failed queue."""
q = Queue()
failed_q = get_failed_queue()
assert (yield from failed_q.count) == 0
assert (yield from q.count) == 0
# NOTE: We have to fake this enqueueing for this test case.
# What we're simulating here is a call to a function that is not
# importable from the worker process.
job = Job.create(func=say_hello, args=(3,))
yield from job.save()
# NOTE: replacement and original strings must have the same length
data = yield from redis.hget(job.key, 'data')
invalid_data = data.replace(b'say_hello', b'fake_attr')
assert data != invalid_data
yield from redis.hset(job.key, 'data', invalid_data)
# We use the low-level internal function to enqueue any data
# (bypassing validity checks)
yield from q.push_job_id(job.id)
assert (yield from q.count) == 1
# All set, we're going to process it
w = Worker([q])
yield from w.work(burst=True, loop=loop) # Should silently pass
assert (yield from q.count) == 0
assert (yield from failed_q.count) == 1
示例8: test_custom_exc_handling
def test_custom_exc_handling(loop):
"""Custom exception handling."""
@asyncio.coroutine
def black_hole(job, *exc_info):
# Don't fall through to default behaviour (moving to failed
# queue)
return False
q = Queue()
failed_q = get_failed_queue()
# Preconditions
assert not (yield from failed_q.count)
assert not (yield from q.count)
# Action
job = yield from q.enqueue(div_by_zero)
assert (yield from q.count) == 1
w = Worker([q], exception_handlers=black_hole)
yield from w.work(burst=True, loop=loop) # Should silently pass
# Postconditions
assert not (yield from q.count)
assert not (yield from failed_q.count)
# Check the job
job = yield from Job.fetch(job.id)
assert job.is_failed
示例9: test_dequeue_deleted_jobs
def test_dequeue_deleted_jobs():
"""Dequeueing deleted jobs from queues don't blow the stack."""
q = Queue()
for _ in range(1, 1000):
job = yield from q.enqueue(say_hello)
yield from job.delete()
yield from q.dequeue()
示例10: test_get_call_string_unicode
def test_get_call_string_unicode(redis):
"""Call string with unicode keyword arguments."""
queue = Queue(connection=redis)
job = yield from queue.enqueue(
echo, arg_with_unicode=UnicodeStringObject())
assert job.get_call_string()
yield from job.perform()
示例11: test_work_via_string_argument
def test_work_via_string_argument(loop):
"""Worker processes work fed via string arguments."""
q = Queue('foo')
w = Worker([q])
job = yield from q.enqueue('fixtures.say_hello', name='Frank')
assert (yield from w.work(burst=True, loop=loop))
assert (yield from job.result) == 'Hi there, Frank!'
示例12: test_empty_remove_jobs
def test_empty_remove_jobs(redis):
"""Emptying a queue deletes the associated job objects."""
q = Queue('example')
job = yield from q.enqueue(lambda x: x)
assert (yield from Job.exists(job.id))
yield from q.empty()
assert not (yield from Job.exists(job.id))
示例13: test_job_access_within_job_function
def test_job_access_within_job_function():
"""The current job is accessible within the job function."""
q = Queue()
# access_self calls get_current_job() and asserts
yield from q.enqueue(access_self)
with SynchronousConnection():
w = SynchronousWorker([SynchronousQueue()])
w.work(burst=True)
示例14: test_work_and_quit
def test_work_and_quit(loop):
"""Worker processes work, then quits."""
fooq, barq = Queue('foo'), Queue('bar')
w = Worker([fooq, barq])
assert not (yield from w.work(burst=True, loop=loop))
yield from fooq.enqueue(say_hello, name='Frank')
assert (yield from w.work(burst=True, loop=loop))
示例15: test_empty_queue
def test_empty_queue(redis):
"""Emptying queues."""
q = Queue('example', connection=redis)
yield from redis.rpush('rq:queue:example', 'foo')
yield from redis.rpush('rq:queue:example', 'bar')
assert not (yield from q.is_empty())
yield from q.empty()
assert (yield from q.is_empty())
assert (yield from redis.lpop('rq:queue:example')) is None