Example #1
0
 def helper_test_get_delay(result):
     import time
     t0 = time.time()
     while not result.ready():
         time.sleep(0.01)
         if time.time() - t0 > 1:
             return None
     return result.get()
Example #2
0
 def helper_test_get_delay(result):
     import time
     t0 = time.time()
     while not result.ready():
         time.sleep(0.01)
         if time.time() - t0 > 1:
             return None
     return result.get()
Example #3
0
    def test_released_from__in_past_is_published_instantly(self):
        publish_on = datetime.now(pytz.UTC) + timedelta(seconds=-1)

        self.workflow.release_period = (publish_on, None)
        transaction.commit()
        result = celery.result.AsyncResult(self.workflow.publish_job_id)
        # Make sure the task is completed before asserting its output:
        assert 'Published.' == result.get()

        self.assertEllipsis("""\
Running job {0.workflow.publish_job_id} for http://xml.zeit.de/online/2007/01/Somalia
Publishing http://xml.zeit.de/online/2007/01/Somalia
...
Done http://xml.zeit.de/online/2007/01/Somalia ...""".format(self),  # noqa
                            self.log.getvalue())
Example #4
0
    def test_eager(self):
        from celery import chord

        @self.app.task(shared=False)
        def addX(x, y):
            return x + y

        @self.app.task(shared=False)
        def sumX(n):
            return sum(n)

        self.app.conf.task_always_eager = True
        x = chord(addX.s(i, i) for i in range(10))
        body = sumX.s()
        result = x(body)
        self.assertEqual(result.get(), sum(i + i for i in range(10)))
Example #5
0
    def test_eager(self):
        from celery import chord

        @self.app.task(shared=False)
        def addX(x, y):
            return x + y

        @self.app.task(shared=False)
        def sumX(n):
            return sum(n)

        self.app.conf.task_always_eager = True
        x = chord(addX.s(i, i) for i in range(10))
        body = sumX.s()
        result = x(body)
        assert result.get() == sum(i + i for i in range(10))
Example #6
0
    def test_eager(self):
        from celery import chord

        @self.app.task(shared=False)
        def addX(x, y):
            return x + y

        @self.app.task(shared=False)
        def sumX(n):
            return sum(n)

        self.app.conf.CELERY_ALWAYS_EAGER = True
        x = chord(addX.s(i, i) for i in range(10))
        body = sumX.s()
        result = x(body)
        self.assertEqual(result.get(), sum(i + i for i in range(10)))
Example #7
0
    def test_eager(self):
        from celery import chord

        @task()
        def addX(x, y):
            return x + y

        @task()
        def sumX(n):
            return sum(n)

        self.app.conf.CELERY_ALWAYS_EAGER = True
        try:
            x = chord(addX.s(i, i) for i in range(10))
            body = sumX.s()
            result = x(body)
            self.assertEqual(result.get(), sum(i + i for i in range(10)))
        finally:
            self.app.conf.CELERY_ALWAYS_EAGER = False
Example #8
0
    def test_released_to__in_past_retracts_instantly(self):
        zeit.cms.workflow.interfaces.IPublish(
            self.content).publish(background=False)
        transaction.commit()

        retract_on = datetime.now(pytz.UTC) + timedelta(seconds=-1)
        self.workflow.release_period = (None, retract_on)
        transaction.commit()

        result = celery.result.AsyncResult(self.workflow.retract_job_id)
        # Make sure the task is completed before asserting its output:
        assert 'Retracted.' == result.get()

        self.assertEllipsis("""...
Running job {0.workflow.retract_job_id} for http://xml.zeit.de/online/2007/01/Somalia
Retracting http://xml.zeit.de/online/2007/01/Somalia
...
Done http://xml.zeit.de/online/2007/01/Somalia ...""".format(self),  # noqa
                            self.log.getvalue())
Example #9
0
    def test_released_from__in_future_is_published_later(self):
        publish_on = datetime.now(pytz.UTC) + timedelta(seconds=1.2)

        self.workflow.release_period = (publish_on, None)
        transaction.commit()

        scheduler = celery_longterm_scheduler.get_scheduler(
            self.layer['celery_app'])
        scheduler.execute_pending(publish_on)
        transaction.commit()

        result = celery.result.AsyncResult(self.workflow.publish_job_id)
        assert 'Published.' == result.get()
        self.assertEllipsis("""\
Start executing tasks...
Enqueuing...
Revoked...
End executing tasks...
Running job {0.workflow.publish_job_id} for http://xml.zeit.de/online/2007/01/Somalia
Publishing http://xml.zeit.de/online/2007/01/Somalia
...
Done http://xml.zeit.de/online/2007/01/Somalia ...""".format(self),  # noqa
                            self.log.getvalue())
Example #10
0
def error_handler(uuid):
    # ToDo: propagate error if the HTTP response hasn't been sent already
    with celery.result.allow_join_result():
        result = celery.result.AsyncResult(uuid)
        ex = result.get(propagate=False)
        utils.LOG.error("Task failed, UUID: {}, error: {}".format(uuid, ex))
Example #11
0
def error_handler(uuid):
    # ToDo: propagate error if the HTTP response hasn't been sent already
    with celery.result.allow_join_result():
        result = celery.result.AsyncResult(uuid)
        ex = result.get(propagate=False)
        utils.LOG.error("Task failed, UUID: {}, error: {}".format(uuid, ex))