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


Python Queue.enqueue方法代码示例

本文整理汇总了Python中aiorq.Queue.enqueue方法的典型用法代码示例。如果您正苦于以下问题:Python Queue.enqueue方法的具体用法?Python Queue.enqueue怎么用?Python Queue.enqueue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在aiorq.Queue的用法示例。


在下文中一共展示了Queue.enqueue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_all_queues

# 需要导入模块: from aiorq import Queue [as 别名]
# 或者: from aiorq.Queue import enqueue [as 别名]
def test_all_queues():
    """All queues"""

    q1 = Queue('first-queue')
    q2 = Queue('second-queue')
    q3 = Queue('third-queue')

    # Ensure a queue is added only once a job is enqueued
    assert not len((yield from Queue.all()))
    yield from q1.enqueue(say_hello)
    assert len((yield from Queue.all())) == 1

    # Ensure this holds true for multiple queues
    yield from q2.enqueue(say_hello)
    yield from q3.enqueue(say_hello)
    names = [q.name for q in (yield from Queue.all())]
    assert len((yield from Queue.all())) == 3

    # Verify names
    assert 'first-queue' in names
    assert 'second-queue' in names
    assert 'third-queue' in names

    # Now empty two queues
    with SynchronousConnection():
        w = SynchronousWorker([SynchronousQueue('second-queue'),
                               SynchronousQueue('third-queue')])
    w.work(burst=True)

    # Queue.all() should still report the empty queues
    assert len((yield from Queue.all())) == 3
开发者ID:essobi,项目名称:aiorq,代码行数:33,代码来源:test_queue.py

示例2: test_worker_sets_job_status

# 需要导入模块: from aiorq import Queue [as 别名]
# 或者: from aiorq.Queue import enqueue [as 别名]
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,代码行数:29,代码来源:test_worker.py

示例3: test_dequeue_any

# 需要导入模块: from aiorq import Queue [as 别名]
# 或者: from aiorq.Queue import enqueue [as 别名]
def test_dequeue_any():
    """Fetching work from any given queue."""

    fooq = Queue('foo')
    barq = Queue('bar')

    assert not (yield from Queue.dequeue_any([fooq, barq], None))

    # Enqueue a single item
    yield from barq.enqueue(say_hello)
    job, queue = yield from Queue.dequeue_any([fooq, barq], None)
    assert job.func == say_hello
    assert queue == barq

    # Enqueue items on both queues
    yield from barq.enqueue(say_hello, 'for Bar')
    yield from fooq.enqueue(say_hello, 'for Foo')

    job, queue = yield from Queue.dequeue_any([fooq, barq], None)
    assert queue == fooq
    assert job.func == say_hello
    assert job.origin == fooq.name
    assert job.args[0] == 'for Foo', 'Foo should be dequeued first.'

    job, queue = yield from Queue.dequeue_any([fooq, barq], None)
    assert queue == barq
    assert job.func == say_hello
    assert job.origin == barq.name
    assert job.args[0] == 'for Bar', 'Bar should be dequeued second.'
开发者ID:essobi,项目名称:aiorq,代码行数:31,代码来源:test_queue.py

示例4: test_create_job_with_ttl_should_expire

# 需要导入模块: from aiorq import Queue [as 别名]
# 或者: from aiorq.Queue import enqueue [as 别名]
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,代码行数:9,代码来源:test_job.py

示例5: test_create_job_with_id

# 需要导入模块: from aiorq import Queue [as 别名]
# 或者: from aiorq.Queue import enqueue [as 别名]
def test_create_job_with_id(redis):
    """Create jobs with a custom ID."""

    queue = Queue(connection=redis)
    job = yield from queue.enqueue(say_hello, job_id="1234")

    assert job.id == "1234"
    yield from job.perform()

    with pytest.raises(TypeError):
        yield from queue.enqueue(say_hello, job_id=1234)
开发者ID:essobi,项目名称:aiorq,代码行数:13,代码来源:test_job.py

示例6: test_remove

# 需要导入模块: from aiorq import Queue [as 别名]
# 或者: from aiorq.Queue import enqueue [as 别名]
def test_remove():
    """Ensure queue.remove properly removes Job from queue."""

    q = Queue('example')
    job = yield from q.enqueue(say_hello)
    assert job.id in (yield from q.job_ids)
    yield from q.remove(job)
    assert job.id not in (yield from q.job_ids)

    job = yield from q.enqueue(say_hello)
    assert job.id in (yield from q.job_ids)
    yield from q.remove(job.id)
    assert job.id not in (yield from q.job_ids)
开发者ID:essobi,项目名称:aiorq,代码行数:15,代码来源:test_queue.py

示例7: test_compact

# 需要导入模块: from aiorq import Queue [as 别名]
# 或者: from aiorq.Queue import enqueue [as 别名]
def test_compact(redis):
    """Queue.compact() removes non-existing jobs."""

    q = Queue()

    yield from q.enqueue(say_hello, 'Alice')
    yield from q.enqueue(say_hello, 'Charlie')
    yield from redis.lpush(q.key, '1', '2')

    assert (yield from q.count) == 4
    yield from q.compact()
    assert (yield from q.count) == 2

    with pytest.raises(RuntimeError):
        len(q)
开发者ID:essobi,项目名称:aiorq,代码行数:17,代码来源:test_queue.py

示例8: test_job_dependency

# 需要导入模块: from aiorq import Queue [as 别名]
# 或者: from aiorq.Queue import enqueue [as 别名]
def test_job_dependency(loop):
    """Enqueue dependent jobs only if their parents don't fail."""

    q = Queue()
    w = Worker([q])
    parent_job = yield from q.enqueue(say_hello)
    job = yield from q.enqueue_call(say_hello, depends_on=parent_job)
    yield from w.work(burst=True, loop=loop)
    job = yield from Job.fetch(job.id)
    assert (yield from job.get_status()) == JobStatus.FINISHED

    parent_job = yield from q.enqueue(div_by_zero)
    job = yield from q.enqueue_call(say_hello, depends_on=parent_job)
    yield from w.work(burst=True, loop=loop)
    job = yield from Job.fetch(job.id)
    assert (yield from job.get_status()) != JobStatus.FINISHED
开发者ID:proofit404,项目名称:aiorq,代码行数:18,代码来源:test_worker.py

示例9: test_work_fails

# 需要导入模块: from aiorq import Queue [as 别名]
# 或者: from aiorq.Queue import enqueue [as 别名]
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,代码行数:35,代码来源:test_worker.py

示例10: test_ttl_via_enqueue

# 需要导入模块: from aiorq import Queue [as 别名]
# 或者: from aiorq.Queue import enqueue [as 别名]
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,代码行数:9,代码来源:test_job.py

示例11: test_create_job_with_ttl_should_have_ttl_after_enqueued

# 需要导入模块: from aiorq import Queue [as 别名]
# 或者: from aiorq.Queue import enqueue [as 别名]
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,代码行数:9,代码来源:test_job.py

示例12: test_custom_exc_handling

# 需要导入模块: from aiorq import Queue [as 别名]
# 或者: from aiorq.Queue import enqueue [as 别名]
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,代码行数:32,代码来源:test_worker.py

示例13: test_dequeue_deleted_jobs

# 需要导入模块: from aiorq import Queue [as 别名]
# 或者: from aiorq.Queue import enqueue [as 别名]
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,代码行数:10,代码来源:test_queue.py

示例14: test_empty_remove_jobs

# 需要导入模块: from aiorq import Queue [as 别名]
# 或者: from aiorq.Queue import enqueue [as 别名]
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,代码行数:10,代码来源:test_queue.py

示例15: test_work_via_string_argument

# 需要导入模块: from aiorq import Queue [as 别名]
# 或者: from aiorq.Queue import enqueue [as 别名]
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,代码行数:10,代码来源:test_worker.py


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