当前位置: 首页>>代码示例>>Python>>正文


Python aiorq.Queue类代码示例

本文整理汇总了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)
开发者ID:proofit404,项目名称:aiorq,代码行数:27,代码来源:test_worker.py

示例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()))
开发者ID:essobi,项目名称:aiorq,代码行数:7,代码来源:test_job.py

示例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
开发者ID:proofit404,项目名称:aiorq,代码行数:33,代码来源:test_worker.py

示例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
开发者ID:essobi,项目名称:aiorq,代码行数:7,代码来源:test_job.py

示例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())
开发者ID:essobi,项目名称:aiorq,代码行数:7,代码来源:test_queue.py

示例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
开发者ID:essobi,项目名称:aiorq,代码行数:7,代码来源:test_job.py

示例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
开发者ID:proofit404,项目名称:aiorq,代码行数:32,代码来源:test_worker.py

示例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
开发者ID:proofit404,项目名称:aiorq,代码行数:30,代码来源:test_worker.py

示例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()
开发者ID:essobi,项目名称:aiorq,代码行数:8,代码来源:test_queue.py

示例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()
开发者ID:essobi,项目名称:aiorq,代码行数:8,代码来源:test_job.py

示例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!'
开发者ID:proofit404,项目名称:aiorq,代码行数:8,代码来源:test_worker.py

示例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))
开发者ID:essobi,项目名称:aiorq,代码行数:8,代码来源:test_queue.py

示例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)
开发者ID:essobi,项目名称:aiorq,代码行数:9,代码来源:test_job.py

示例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))
开发者ID:proofit404,项目名称:aiorq,代码行数:9,代码来源:test_worker.py

示例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
开发者ID:essobi,项目名称:aiorq,代码行数:10,代码来源:test_queue.py


注:本文中的aiorq.Queue类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。