| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 | ======================================================= Example Celery project using a database message queue=======================================================Short instructions==================Quick rundown of the tutorial::1. Install the `ghettoq`_ plugin.    $ pip install ghettoq    $ celeryinit2. Open up two terminals. In the first, run:    $ celeryd --loglevel=INFO  In the second you run the test program:    $ python ./test.pyVoila, you've executed some tasks!Instructions============This example uses the database as a message queue (commonly called a "ghettoqueue"). Excellent for testing, but not suitable for productioninstallations.To try it out you have to install the `GhettoQ`_ package first::    $ pip install ghettoqThis package is an add-on to `Carrot`_; the messaging abstraction celeryuses. The add-on enables the use of databases as message queues. Currently itsupports `Redis`_ and relational databases via the Django ORM... _`ghettoq`: http://pypi.python.org/pypi/ghettoq.. _`Carrot`: http://pypi.python.org/pypi/carrot.. _`Redis`: http://code.google.com/p/redis/The provided ``celeryconfig.py`` configures the settings used to drive celery.Next we have to create the database tables by issuing the ``celeryinit``command::    $ celeryinitWe're using SQLite3, so this creates a database file (``celery.db`` asspecified in the config file). SQLite is great, but when used in combinationwith Django it doesn't handle concurrency well. To protect your program fromlock problems, celeryd will only spawn one worker process. Withother database drivers you can specify as many worker processes as you want.With the setup done, let's run the worker::    $ celeryd --loglevel=INFOYou should see the worker starting up. As it will continue running inthe foreground, we have to open up another terminal to run our test program::    $ python test.pyThe test program simply runs the ``add`` task, which is a simple task addingnumbers. You can also run the task manually if you want::    >>> from tasks import add    >>> result = add.delay(4, 4)    >>> result.wait()    8Using Redis instead===================To use redis instead, you have to configure the following directives in ``celeryconfig.py``::    CARROT_BACKEND = "ghettoq.taproot.Redis"    BROKER_HOST = "localhost"    BROKER_PORT = 6379Modules=======    * celeryconfig.py        The celery configuration module.    * tasks.py        Tasks are defined in this module. This module is automatically        imported by the worker because it's listed in        celeryconfig's ``CELERY_IMPORTS`` directive.    * test.py        Simple test program running tasks.More information================http://celeryproject.org
 |