本文整理匯總了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)