Пример #1
0
 def setUp(self):
     job = Job.create(func=div_by_zero, args=(1, 2, 3))
     job.origin = 'fake'
     job.timeout = 200
     job.save()
     self.job = job
     self.fq = get_failed_queue()
Пример #2
0
 def setUp(self):
     self.q = Queue()
     self.q.save()
     self.job = Job.create(
         func=say_hello,
         args=('Nick',),
         kwargs=dict(foo='bar')
     )
Пример #3
0
    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)
Пример #4
0
 def setUp(self):
     self.q = Queue()
     self.job = Job.create(func=some_calculation,
         args=(3, 4),
         kwargs=dict(z=2),
         repeat=1,
         interval=60)
     self.job.save()
Пример #5
0
    def test_create_job_from_string_function(self):
        """Creation of jobs using string specifier."""
        job = Job.create(func='test_pq.fixtures.say_hello', args=('World',))

        # Job data is set
        self.assertEquals(job.func, say_hello)
        self.assertIsNone(job.instance)
        self.assertEquals(job.args, ('World',))
Пример #6
0
    def test_create_job_from_string_function(self):
        """Creation of jobs using string specifier."""
        job = Job.create(func='test_pq.fixtures.say_hello', args=('World', ))

        # Job data is set
        self.assertEquals(job.func, say_hello)
        self.assertIsNone(job.instance)
        self.assertEquals(job.args, ('World', ))
Пример #7
0
 def test_job_get_schedule_options(self):
     """Test the job schedule property"""
     j = Job.create(do_nothing,
                    interval=600,
                    between='2-4',
                    repeat=10,
                    weekdays=(0, 1, 2))
     self.assertIsNotNone(j.get_schedule_options())
Пример #8
0
    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.assertEquals(job.id, self.job.id)
        self.assertIsNone(promise)
Пример #9
0
    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.assertEquals(job.id, self.job.id)
        self.assertIsNone(promise)
Пример #10
0
    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)
Пример #11
0
    def test_create_instance_method_job(self):
        """Creation of jobs for instance methods."""
        c = Calculator(2)
        job = Job.create(func=c.calculate, args=(3, 4))

        # Job data is set
        self.assertEquals(job.func, c.calculate)
        self.assertEquals(job.instance, c)
        self.assertEquals(job.args, (3, 4))
Пример #12
0
    def test_create_instance_method_job(self):
        """Creation of jobs for instance methods."""
        c = Calculator(2)
        job = Job.create(func=c.calculate, args=(3, 4))

        # Job data is set
        self.assertEquals(job.func, c.calculate)
        self.assertEquals(job.instance, c)
        self.assertEquals(job.args, (3, 4))
Пример #13
0
    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)
Пример #14
0
    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)
Пример #15
0
 def test_job_get_schedule_options(self):
     """Test the job schedule property"""
     j = Job.create(
         do_nothing,
         interval=600,
         between='2-4',
         repeat=10,
         weekdays=(0,1,2)
         )
     self.assertIsNotNone(j.get_schedule_options())
Пример #16
0
 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)
Пример #17
0
 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)
Пример #18
0
    def test_job_create(self):
        job = Job.create(func=some_calculation, args=(3, 4), kwargs=dict(z=2))

        self.assertIsNotNone(job.created_at)
        self.assertIsNotNone(job.description)
        self.assertIsNone(job.instance)

        # Job data is set...
        self.assertEquals(job.func, some_calculation)
        self.assertEquals(job.args, (3, 4))
        self.assertEquals(job.kwargs, {'z': 2})

        # ...but metadata is not
        self.assertIsNone(job.origin)
        self.assertIsNone(job.enqueued_at)
Пример #19
0
    def test_job_create(self):
        job = Job.create(func=some_calculation, args=(3, 4), kwargs=dict(z=2))

        self.assertIsNotNone(job.created_at)
        self.assertIsNotNone(job.description)
        self.assertIsNone(job.instance)

        # Job data is set...
        self.assertEquals(job.func, some_calculation)
        self.assertEquals(job.args, (3, 4))
        self.assertEquals(job.kwargs, {'z': 2})

        # ...but metadata is not
        self.assertIsNone(job.origin)
        self.assertIsNone(job.enqueued_at)
Пример #20
0
 def test_scheduled_job_create(self):
     """ Test extra kwargs """
     dt = datetime(2013,1,1, tzinfo=utc)
     rd = relativedelta(months=1, days=-1)
     job = Job.create(func=some_calculation,
         args=(3, 4), kwargs=dict(z=2),
         scheduled_for = dt,
         repeat = -1,
         interval = rd,
         between = '0-24'
         )
     job.save()
     job = Job.objects.get(pk=job.id)
     self.assertEqual(rd, job.interval)
     self.assertEqual(dt, job.scheduled_for)
Пример #21
0
 def test_scheduled_job_create(self):
     """ Test extra kwargs """
     dt = datetime(2013, 1, 1, tzinfo=utc)
     rd = relativedelta(months=1, days=-1)
     job = Job.create(func=some_calculation,
                      args=(3, 4),
                      kwargs=dict(z=2),
                      scheduled_for=dt,
                      repeat=-1,
                      interval=rd,
                      between='0-24')
     job.save()
     job = Job.objects.get(pk=job.id)
     self.assertEqual(rd, job.interval)
     self.assertEqual(dt, job.scheduled_for)
Пример #22
0
    def test_work_is_unreadable(self):
        """Unreadable jobs are put on the failed queue."""

        self.assertEqual(self.fq.count, 0)
        self.assertEqual(self.q.count, 0)

        # NOTE: We have to fake this enqueueing for this test case.
        # What we're simulating here is a call to a function that is not
        # importable from the worker process.
        job = Job.create(func=div_by_zero, args=(3,))
        job.save()
        job.instance = 'nonexisting_job'
        job.queue = self.q
        job.save()

        self.assertEqual(self.q.count, 1)

        # All set, we're going to process it

        self.w.work(burst=True)  # should silently pass
        self.assertEqual(self.q.count, 0)
        self.assertEqual(self.fq.count, 1)
Пример #23
0
    def test_work_is_unreadable(self):
        """Unreadable jobs are put on the failed queue."""

        self.assertEquals(self.fq.count, 0)
        self.assertEquals(self.q.count, 0)

        # NOTE: We have to fake this enqueueing for this test case.
        # What we're simulating here is a call to a function that is not
        # importable from the worker process.
        job = Job.create(func=div_by_zero, args=(3, ))
        job.save()
        job.instance = 'nonexisting_job'
        job.queue = self.q
        job.save()

        self.assertEquals(self.q.count, 1)

        # All set, we're going to process it

        self.w.work(burst=True)  # should silently pass
        self.assertEquals(self.q.count, 0)
        self.assertEquals(self.fq.count, 1)
Пример #24
0
 def setUp(self):
     self.job = Job.create(func=some_calculation, args=(3, 4), kwargs=dict(z=2))
Пример #25
0
 def setUp(self):
     self.job = Job.create(func=some_calculation,
                           args=(3, 4),
                           kwargs=dict(z=2))
Пример #26
0
 def setUp(self):
     job = Job.create(func=div_by_zero, args=(1, 2, 3))
     job.origin = 'fake'
     job.save()
     self.job = job