當前位置: 首頁>>代碼示例>>Python>>正文


Python Queue.count_delayed_jobs方法代碼示例

本文整理匯總了Python中limpyd_jobs.models.Queue.count_delayed_jobs方法的典型用法代碼示例。如果您正苦於以下問題:Python Queue.count_delayed_jobs方法的具體用法?Python Queue.count_delayed_jobs怎麽用?Python Queue.count_delayed_jobs使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在limpyd_jobs.models.Queue的用法示例。


在下文中一共展示了Queue.count_delayed_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_delayed_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_delayed_jobs_should_return_the_number_of_delayed_jobs

# 需要導入模塊: from limpyd_jobs.models import Queue [as 別名]
# 或者: from limpyd_jobs.models.Queue import count_delayed_jobs [as 別名]
 def test_count_delayed_jobs_should_return_the_number_of_delayed_jobs(self):
     self.assertEqual(Queue.count_delayed_jobs('test'), 0)
     Job.add_job(identifier='job:1', queue_name='test', delayed_for=5)
     self.assertEqual(Queue.count_delayed_jobs('test'), 1)
     Job.add_job(identifier='job:2', queue_name='test')
     self.assertEqual(Queue.count_delayed_jobs('test'), 1)
     Job.add_job(identifier='foo:1', queue_name='foo', delayed_for=5)
     Job.add_job(identifier='bar:1', queue_name='bar', delayed_for=5)
     self.assertEqual(Queue.count_delayed_jobs(['foo', 'bar']), 2)
     self.assertEqual(Queue.count_delayed_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_delayed_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_delayed_jobs方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。