def test_store_result(self): b = AMQPBackend(self.app) tid = uuid() request = Context(args=(1, 2, 3), kwargs={'foo': 'bar'}, task_name='mytask', retries=2, hostname='celery@worker_1', delivery_info={'routing_key': 'celery'}) b.store_result(tid, {'fizz': 'buzz'}, states.SUCCESS, request=request) meta = b.get_task_meta(tid) assert meta == { 'args': [1, 2, 3], 'children': [], 'kwargs': {'foo': 'bar'}, 'name': 'mytask', 'queue': 'celery', 'result': {'fizz': 'buzz'}, 'retries': 2, 'status': 'SUCCESS', 'task_id': tid, 'traceback': None, 'worker': 'celery@worker_1', }
def test_consume_raises_inner_block(self): with patch('kombu.connection.Connection.drain_events') as drain: def se(*args, **kwargs): drain.side_effect = ValueError() raise KeyError('foo') drain.side_effect = se b = AMQPBackend(self.app) with self.assertRaises(ValueError): next(b.consume('id1'))
def test_store_result_retries(self): iterations = [0] stop_raising_at = [5] def publish(*args, **kwargs): if iterations[0] > stop_raising_at[0]: return iterations[0] += 1 raise KeyError('foo') backend = AMQPBackend(self.app) from celery.app.amqp import Producer prod, Producer.publish = Producer.publish, publish try: with self.assertRaises(KeyError): backend.retry_policy['max_retries'] = None backend.store_result('foo', 'bar', 'STARTED') with self.assertRaises(KeyError): backend.retry_policy['max_retries'] = 10 backend.store_result('foo', 'bar', 'STARTED') finally: Producer.publish = prod
def test_store_result_retries(self): iterations = [0] stop_raising_at = [5] def publish(*args, **kwargs): if iterations[0] > stop_raising_at[0]: return iterations[0] += 1 raise KeyError("foo") backend = AMQPBackend() from celery.app.amqp import TaskProducer prod, TaskProducer.publish = TaskProducer.publish, publish try: with self.assertRaises(KeyError): backend.retry_policy["max_retries"] = None backend.store_result("foo", "bar", "STARTED") with self.assertRaises(KeyError): backend.retry_policy["max_retries"] = 10 backend.store_result("foo", "bar", "STARTED") finally: TaskProducer.publish = prod
def create_backend(self, **opts): opts = dict(dict(serializer='pickle', persistent=True), **opts) return AMQPBackend(self.app, **opts)
def test_get_many_raises_inner_block(self): with patch('kombu.connection.Connection.drain_events') as drain: drain.side_effect = KeyError('foo') b = AMQPBackend(self.app) with self.assertRaises(KeyError): next(b.get_many(['id1']))
def create_backend(self, **opts): opts = dict({'serializer': 'pickle', 'persistent': True}, **opts) return AMQPBackend(self.app, **opts)
def create_backend(self, **opts): opts = dict(dict(serializer="pickle", persistent=False), **opts) return AMQPBackend(**opts)
def create_backend(self): return AMQPBackend(serializer="pickle", persistent=False)
from __future__ import absolute_import, unicode_literals from .celery import app from celery.utils.log import get_task_logger from celery.backends.amqp import AMQPBackend import time log = get_task_logger(__name__) @app.task(backend=AMQPBackend(app, url='amqp://')) def add(x, y): log.info('Calling task add(%d, %d)' % (x, y)) print('I am in task add') z = sum(x, y) return z def sum(x, y): time.sleep(10) return (x + y)