Esempio n. 1
0
    def test_receieve_message(self):
        l = Consumer(self.ready_queue, timer=self.timer)
        m = create_message(Mock(), task=foo_task.name,
                           args=[2, 4, 8], kwargs={})
        l.update_strategies()
        callback = self._get_on_message(l)
        callback(m.decode(), m)

        in_bucket = self.ready_queue.get_nowait()
        self.assertIsInstance(in_bucket, Request)
        self.assertEqual(in_bucket.name, foo_task.name)
        self.assertEqual(in_bucket.execute(), 2 * 4 * 8)
        self.assertTrue(self.timer.empty())
Esempio n. 2
0
    def test_receieve_message(self):
        l = Consumer(self.ready_queue, timer=self.timer)
        m = create_message(Mock(),
                           task=foo_task.name,
                           args=[2, 4, 8],
                           kwargs={})
        l.update_strategies()
        callback = self._get_on_message(l)
        callback(m.decode(), m)

        in_bucket = self.ready_queue.get_nowait()
        self.assertIsInstance(in_bucket, Request)
        self.assertEqual(in_bucket.name, foo_task.name)
        self.assertEqual(in_bucket.execute(), 2 * 4 * 8)
        self.assertTrue(self.timer.empty())
Esempio n. 3
0
@task(accept_magic_kwargs=False)
def T():
    pass


tid = uuid()
P = TaskPool()
hostname = socket.gethostname()
task = {'task': T.name, 'args': (), 'kwargs': {}, 'id': tid, 'flags': 0}
app = current_app._get_current_object()


def on_task(req):
    req.execute_using_pool(P)


def on_ack(*a):
    pass


m = Message(None, {}, {}, task)

x = Consumer(on_task, hostname=hostname, app=app)
x.update_strategies()
name = T.name
ts = time()
for i in range(100000):
    x.strategies[name](m, m.body, on_ack)
print(time() - ts)
Esempio n. 4
0
File: req.py Progetto: Dalar/celery
import sys

@task(accept_magic_kwargs=False)
def T():
    pass

tid = uuid()
P = TaskPool()
hostname = socket.gethostname()
task = {'task': T.name, 'args': (), 'kwargs': {}, 'id': tid, 'flags': 0}
app = current_app._get_current_object()
ready_queue = Queue()

def on_put(req):
    req.execute_using_pool(P)

def on_ack(*a): pass


m = Message(None, {}, {}, task)

ready_queue.put = on_put
x = Consumer(ready_queue, hostname=hostname, app=app)
x.update_strategies()
name = T.name
ts = time()
for i in range(100000):
    x.strategies[name](m, m.body, on_ack)
print(time() - ts)