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


Python Queue.count_waiting_jobs方法代码示例

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


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

示例1: test_requeue_delayed_jobs_put_back_ready_delayed_jobs_to_the_waiting_list

# 需要导入模块: from limpyd_jobs.models import Queue [as 别名]
# 或者: from limpyd_jobs.models.Queue import count_waiting_jobs [as 别名]
    def test_requeue_delayed_jobs_put_back_ready_delayed_jobs_to_the_waiting_list(self):
        queue = Queue.get_queue(name='test')

        job1 = Job.add_job(identifier='job:1', queue_name='test', delayed_for=10)
        job2 = Job.add_job(identifier='job:2', queue_name='test', delayed_for=1)

        self.assertEqual(Queue.count_waiting_jobs('test'), 0)
        self.assertEqual(Queue.count_delayed_jobs('test'), 2)

        self.assertEqual(job1.status.hget(), STATUSES.DELAYED)
        self.assertEqual(job2.status.hget(), STATUSES.DELAYED)

        # must not move any jobs, too soon
        queue.requeue_delayed_jobs()
        self.assertEqual(Queue.count_waiting_jobs('test'), 0)
        self.assertEqual(Queue.count_delayed_jobs('test'), 2)

        self.assertEqual(job1.status.hget(), STATUSES.DELAYED)
        self.assertEqual(job2.status.hget(), STATUSES.DELAYED)

        sleep(1)

        # now we should have one job in the waiting list
        queue.requeue_delayed_jobs()
        self.assertEqual(Queue.count_waiting_jobs('test'), 1)
        self.assertEqual(Queue.count_delayed_jobs('test'), 1)

        self.assertEqual(job1.status.hget(), STATUSES.DELAYED)
        self.assertEqual(job2.status.hget(), STATUSES.WAITING)

        waiting_jobs = queue.waiting.lmembers()
        self.assertEqual(waiting_jobs, [job2.ident])
        delayed_jobs = queue.delayed.zrange(0, -1, withscores=True)
        self.assertEqual(delayed_jobs[0][0], job1.ident)
开发者ID:limpyd,项目名称:redis-limpyd-jobs,代码行数:36,代码来源:models.py

示例2: test_count_waiting_jobs_should_return_the_number_of_waiting_jobs

# 需要导入模块: from limpyd_jobs.models import Queue [as 别名]
# 或者: from limpyd_jobs.models.Queue import count_waiting_jobs [as 别名]
 def test_count_waiting_jobs_should_return_the_number_of_waiting_jobs(self):
     self.assertEqual(Queue.count_waiting_jobs('test'), 0)
     Job.add_job(identifier='job:1', queue_name='test')
     self.assertEqual(Queue.count_waiting_jobs('test'), 1)
     Job.add_job(identifier='job:2', queue_name='test', delayed_for=5)
     self.assertEqual(Queue.count_waiting_jobs('test'), 1)
     Job.add_job(identifier='foo:1', queue_name='foo')
     Job.add_job(identifier='bar:1', queue_name='bar')
     self.assertEqual(Queue.count_waiting_jobs(['foo', 'bar']), 2)
     self.assertEqual(Queue.count_waiting_jobs(['test', 'foo', 'bar']), 3)
开发者ID:limpyd,项目名称:redis-limpyd-jobs,代码行数:12,代码来源:models.py

示例3: test_requeue_delayed_jobs_should_abort_if_another_thread_works_on_it

# 需要导入模块: from limpyd_jobs.models import Queue [as 别名]
# 或者: from limpyd_jobs.models.Queue import count_waiting_jobs [as 别名]
    def test_requeue_delayed_jobs_should_abort_if_another_thread_works_on_it(self):
        queue = Queue.get_queue(name='test')

        # simulate a lock on this queue
        lock_key = queue.make_key(
            queue._name,
            queue.pk.get(),
            "requeue_all_delayed_ready_jobs",
        )

        queue.get_connection().set(lock_key, 1)

        Job.add_job(identifier='job:1', queue_name='test', delayed_for=0.1)
        self.assertEqual(Queue.count_waiting_jobs('test'), 0)
        self.assertEqual(Queue.count_delayed_jobs('test'), 1)

        # wait until the job should be ready
        sleep(0.5)

        queue.requeue_delayed_jobs()

        # the requeue must have done nothing
        self.assertEqual(Queue.count_waiting_jobs('test'), 0)
        self.assertEqual(Queue.count_delayed_jobs('test'), 1)
开发者ID:limpyd,项目名称:redis-limpyd-jobs,代码行数:26,代码来源:models.py


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