views:

534

answers:

2

I'm using Carrot for a message queue in a Django project and followed the tutorial, and it works fine. But the example runs in the console, and I'm wondering how I apply this in Django. The publisher class I'm calling from one of my models in models.py, so that's OK. But I have no idea where to put the consumer class.

Since it just sits there with .wait(), I don't know at what point or where I need to instantiate it so that it's always running and listening for messages!

Thanks!

+5  A: 

The consumer is simply a long running script in the example you cite from the tutorial. It pops a message from the queue, does something, then calls wait and essentially goes to sleep until another message comes in.

This script could just be running at the console under your account or configured as a unix daemon or a win32 service. In production, you'd want to make sure that if it dies, it can be restarted, etc (a daemon or service would be more appropriate here).

Or you could take out the wait call and run it under the windows scheduler or as a cron job. So it processes the queue every n minutes or something and exits. It really depends on your application requirements, how fast your queue is filling up, etc.

Does that make sense or have I totally missed what you were asking?

ars
A: 

If what you are doing is processing tasks, please check out celery: http://github.com/ask/celery/

asksol
Thanks, asksol. When I asked the question before:http://stackoverflow.com/questions/1102254/should-i-use-celery-or-carrot-for-a-django-projectThe answer seems to have been use celery if running scheduled tasks on different machines. I don't plan on using different machines, but I do want to place tasks onto a queue. Do you still think celery is the appropriate thing to use and not carrot?
rick
Sure. The number of machines doesn't matter. You can run celeryd on the same machine. If that isn't enough at some point, you can add more servers processing tasks.
asksol