AMQP based worker/master pattern framework
Project description
AMQP based RPC library for Tornado
Use cases
Task queue
Load balancing for different CPU-bound HTTP handlers
… other systems which involve RPC
Installation
pip install crew
Example
See the full example.
Usage
For example create your first app, and save as master.py:
import tornado.ioloop import tornado.gen import tornado.web import tornado.log import json import tornado.options from crew import TimeoutError, ExpirationError from crew.master.tornado import Client class MainHandler(tornado.web.RequestHandler): @tornado.gen.coroutine def get(self): resp = yield self.settings['crew'].call(None, priority=100) self.write(json.dumps(resp) cl = Client() application = tornado.web.Application( [ (r"/", MainHandler), ], crew=cl, autoreload=True, debug=True, ) if __name__ == "__main__": cl.connect() tornado.options.parse_command_line() application.listen(8888) tornado.ioloop.IOLoop.instance().start()
And create your first task, and save as worker.py:
# encoding: utf-8 from crew.worker import run, context, Task @Task('test') def long_task(req): context.settings.counter += 1 return {"counter": context.settings.counter} run( counter=0 )
After that run it:
$ python master.py & $ python worker.py & $ wait
Try to test it:
$ curl http://localhost:8888/
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
crew-0.9.0.tar.gz
(10.8 kB
view hashes)
Built Distributions
crew-0.9.0-py2.7.egg
(16.1 kB
view hashes)
crew-0.9.0-py2-none-any.whl
(18.3 kB
view hashes)
Close
Hashes for crew-0.9.0.macosx-10.11-x86_64.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | c3b330a4bab191a819892080ed1a12c5003d3b5740ed216af29a5c2036198486 |
|
MD5 | be8b7ba01c469f37586645c84078dbe6 |
|
BLAKE2b-256 | 0c8cc2c0bc7735717cbc9e793550fde6657acfeb77f08c05671b6a01d0309da6 |