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')
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')
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')
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')
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()