本文整理汇总了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)
示例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)
示例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)