Example #1
0
 def test_declare_task(self):
     app = WorkerApplication()
     app.tasks = MagicMock()
     app.declare_task('taskname', 'testexchange', 'testroutingkey')
     app.tasks._declare.assert_called_with('taskname',
                                           exchange='testexchange',
                                           routing_key='testroutingkey')
Example #2
0
 def test_declare_task(self):
     app = WorkerApplication()
     app.tasks = MagicMock()
     app.declare_task('taskname', 'testexchange', 'testroutingkey')
     app.tasks._declare.assert_called_with('taskname',
                                           exchange='testexchange',
                                           routing_key='testroutingkey')
Example #3
0
def register(master, config):
    with AmqpConnection() as channel:
        channel.queue_declare('do_work')

    app = WorkerApplication()
    app.register_task(do_work)
    master.add_worker(app, ['do_work'], num_processes=4)
Example #4
0
 def test_register_module(self):
     app = WorkerApplication()
     app.declare_task = MagicMock()
     app.register_task = MagicMock()
     mod = MagicMock()
     mod.__all__ = ['func1', 'func2']
     mod.func1 = MagicMock(__name__='func1')
     mod.func2 = MagicMock(__name__='func2')
     app.register_module(mod, 't_', routing_key='testroutingkey')
     app.register_task.assert_any_call(mod.func1, 't_func1',
                                       routing_key='testroutingkey')
     app.register_task.assert_any_call(mod.func2, 't_func2',
                                       routing_key='testroutingkey')
Example #5
0
 def test_register_module(self):
     app = WorkerApplication()
     app.declare_task = MagicMock()
     app.register_task = MagicMock()
     mod = MagicMock()
     mod.__all__ = ['func1', 'func2']
     mod.func1 = MagicMock(__name__='func1')
     mod.func2 = MagicMock(__name__='func2')
     app.register_module(mod, 't_', routing_key='testroutingkey')
     app.register_task.assert_any_call(mod.func1,
                                       't_func1',
                                       routing_key='testroutingkey')
     app.register_task.assert_any_call(mod.func2,
                                       't_func2',
                                       routing_key='testroutingkey')
Example #6
0
    def test_register_task(self):
        @routing_info('testexchange')
        def func1():
            pass

        def func2():
            pass

        app = WorkerApplication()
        app.tasks = MagicMock()
        app.register_task(func1, 'funcone', routing_key='testroutingkey')
        app.tasks._set.assert_called_with(func1,
                                          'funcone',
                                          exchange='testexchange',
                                          routing_key='testroutingkey')
        app.register_task(func2, exchange='testexchange')
        app.tasks._set.assert_called_with(func2,
                                          'func2',
                                          exchange='testexchange',
                                          routing_key=None)
Example #7
0
    def test_register_task(self):
        @routing_info('testexchange')
        def func1():
            pass

        def func2():
            pass
        app = WorkerApplication()
        app.tasks = MagicMock()
        app.register_task(func1, 'funcone', routing_key='testroutingkey')
        app.tasks._set.assert_called_with(func1, 'funcone',
                                          exchange='testexchange',
                                          routing_key='testroutingkey')
        app.register_task(func2, exchange='testexchange')
        app.tasks._set.assert_called_with(func2, 'func2',
                                          exchange='testexchange',
                                          routing_key=None)
Example #8
0
from __future__ import print_function

import sys

from provoke.app import WorkerApplication
from provoke.amqp import AmqpConnection

with AmqpConnection() as channel:
    channel.queue_declare('do_work')

app = WorkerApplication()
app.declare_task('do_work')

args = sys.argv[1:] or ['World!', 'Hello']
print('Sending:', ' '.join(args))
res = app.tasks.do_work.apply_async(args, send_result=True)
print('Received result:', ' '.join(res.get()))
res.delete()