celery

Distributed Task Queue for Django
Download

celery Ranking & Summary

Advertisement

  • Rating:
  • License:
  • BSD License
  • Price:
  • FREE
  • Publisher Name:
  • Ask Solem
  • Publisher web site:
  • http://search.cpan.org/~asksh/Modwheel-0.3.3/lib/Modwheel.pm

celery Tags


celery Description

Distributed Task Queue for Django celery is a distributed task queue framework for Django.InstallationYou can install celery either via the Python Package Index (PyPI) or from source.To install using pip,:$ pip install celeryTo install using easy_install,:$ easy_install celeryIf you have downloaded a source tarball you can install it by doing the following,:$ python setup.py build# python setup.py install # as rootUsageHave to write a cool tutorial, but here is some simple usage info.Note You need to have a AMQP message broker running, like RabbitMQ, and you need to have the amqp server setup in your settings file, as described in the carrot distribution README.Note If you're running SQLite as the database backend, celeryd will only be able to process one message at a time, this because SQLite doesn't allow concurrent writes.Defining tasks >>> from celery.task import tasks >>> from celery.log import setup_logger >>> def do_something(some_arg, **kwargs): ... logger = setup_logger(**kwargs) ... logger.info("Did something: %s" % some_arg) >>> task.register(do_something, "do_something")Note Task functions only supports keyword arguments.Tell the celery daemon to run a task >>> from celery.task import delay_task >>> delay_task("do_something", some_arg="foo bar baz")Running the celery daemon$ cd mydjangoproject$ env DJANGO_SETTINGS_MODULE=settings celeryd Did something: foo bar baz Waiting for queue.Autodiscovery of taskscelery has an autodiscovery feature like the Django Admin, that automatically loads any tasks.py module in the applications listed in settings.INSTALLED_APPS.A good place to add this command could be in your urls.py,from celery.task import taskstasks.autodiscover()Then you can add new tasks in your applications tasks.py module,from celery.task import tasksfrom celery.log import setup_loggerfrom clickcounter.models import ClickCountdef increment_click(for_url, **kwargs): logger = setup_logger(**kwargs) clicks_for_url, cr = ClickCount.objects.get_or_create(url=for_url) clicks_for_url.clicks = clicks_for_url.clicks + 1 clicks_for_url.save() logger.info("Incremented click count for %s (not at %d)" % ( for_url, clicks_for_url.clicks)tasks.register(increment_click, "increment_click")Periodic TasksPeriodic tasks are tasks that are run every n seconds. They don't support extra arguments. Here's an example of a periodic task: >>> from celery.task import tasks, PeriodicTask >>> from datetime import timedelta >>> class MyPeriodicTask(PeriodicTask): ... name = "foo.my-periodic-task" ... run_every = timedelta(seconds=30) ... ... def run(self, **kwargs): ... logger = self.get_logger(**kwargs) ... logger.info("Running periodic task!") ... >>> tasks.register(MyPeriodicTask)For periodic tasks to work you need to add celery to INSTALLED_APPS, and issue a syncdb. Requirements: · Python · Django What's New in This Release: · It's getting quite stable, with a lot of new features, so bump version to 0.2. This is a pre-release. · celery.task.mark_as_read() and celery.task.mark_as_failure() has been removed. Use celery.backends.default_backend.mark_as_read(), and celery.backends.default_backend.mark_as_failure() instead.


celery Related Software