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 jaon 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.6.3.tar.gz
(7.6 kB
view details)
File details
Details for the file crew-0.6.3.tar.gz
.
File metadata
- Download URL: crew-0.6.3.tar.gz
- Upload date:
- Size: 7.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | add2a1dbf8e5c59367183fda1d8b03e521a317884dea8bf79d5323c48a4f4db5 |
|
MD5 | fba86e70316f794f63856cde8071f3ba |
|
BLAKE2b-256 | e000aaf9d63bb7a6087f5e741ffc4495035ae648a60543400cf1569e2bdd1ffc |