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


Python Queue.schedule_call方法代码示例

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


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

示例1: TestScheduleJobs

# 需要导入模块: from pq import Queue [as 别名]
# 或者: from pq.Queue import schedule_call [as 别名]
class TestScheduleJobs(TransactionTestCase):

    def setUp(self):
        self.q = Queue()
        self.w = Worker.create([self.q])

    def test_shedule_call(self):
        """Schedule to fire now"""
        job = self.q.schedule_call(now(), do_nothing)
        self.w.work(burst=True)
        with self.assertRaises(Job.DoesNotExist) as exc:
            Job.objects.get(queue_id='default', pk=job.id)

    def test_schedule_future_call(self):
        """Schedule to fire in the distant future"""
        job = self.q.schedule_call(datetime(2999,12,1, tzinfo=utc), do_nothing)
        self.w.work(burst=True)
        # check it is still in the queue
        self.assertIsNotNone(Job.objects.get(queue_id='default', pk=job.id))
开发者ID:vladignatyev,项目名称:django-pq,代码行数:21,代码来源:test_queue.py

示例2: Test_get_job_or_promise

# 需要导入模块: from pq import Queue [as 别名]
# 或者: from pq.Queue import schedule_call [as 别名]
class Test_get_job_or_promise(TransactionTestCase):
    """Test the Job._get_job_or_promise classmethod"""

    def setUp(self):
        self.q = Queue(scheduled=True)
        # simulate the default worker timeout
        self.timeout = 60
        future = now() + timedelta(seconds=self.timeout/2)
        # enqueue a job for 30 seconds time in the future
        self.job = self.q.schedule_call(future, do_nothing)


    def test_get_job_or_promise(self):
        """Test get a promise of a job in the future"""

        job, promise, timeout = Job._get_job_or_promise(
            self.q.connection, self.q, self.timeout)
        self.assertLessEqual(timeout, self.timeout)
        self.assertIsNone(job)
        self.assertEqual(promise, self.q.name)

    def test_get_no_job_no_promise(self):
        """Test get no job and no promise"""

        # job is in the future beyond the current
        # worker timeout
        job, promise, timeout = Job._get_job_or_promise(
            self.q.connection, self.q, 1)
        self.assertEqual(timeout, 1)
        self.assertIsNone(job)
        self.assertIsNone(promise)

    def test_get_earlier_job_no_promise(self):
        """Test get earlier job and no promise"""
        # Job enqueue after the first scheduled job
        # but to be exec ahead of the scheduled job
        now_job = self.q.enqueue(do_nothing)
        job, promise, timeout = Job._get_job_or_promise(
            self.q.connection, self.q, 60)
        # timeout should remain the same
        self.assertEqual(timeout, 60)
        self.assertEqual(now_job.id, job.id)
        self.assertIsNone(promise)
开发者ID:JirkaV,项目名称:django-pq,代码行数:45,代码来源:test_job.py

示例3: TestGetJobNoPromise

# 需要导入模块: from pq import Queue [as 别名]
# 或者: from pq.Queue import schedule_call [as 别名]
class TestGetJobNoPromise(TransactionTestCase):
    def setUp(self):
        # setup a job in the very near future which
        # should execute
        self.q = Queue(scheduled=True)
        # simulate the default worker timeout
        self.timeout = 60
        future = now() + timedelta(seconds=1)
        # enqueue a job for 1 second time in the future
        self.job = self.q.schedule_call(future, do_nothing)
        time.sleep(1)

    def test_get_job_no_promise(self):
        """Test get job and no promise"""

        job, promise, timeout = Job._get_job_or_promise(
            self.q.connection, self.q, self.timeout)
        self.assertEqual(timeout, self.timeout)
        self.assertEqual(job.id, self.job.id)
        self.assertIsNone(promise)
开发者ID:oinopion,项目名称:django-pq,代码行数:22,代码来源:test_job.py


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