This document describes an older version of Celery (2.5). For the latest stable version please go here.

celery.task

celery.task

Creating tasks, subtasks, sets and chords.

copyright:
  1. 2009 - 2012 by Ask Solem.
license:

BSD, see LICENSE for more details.

celery.task.task(*args, **kwargs)

Decorator to create a task class out of any callable.

Examples

@task
def refresh_feed(url):
    return Feed.objects.get(url=url).refresh()

With setting extra options and using retry.

@task(max_retries=10)
def refresh_feed(url):
    try:
        return Feed.objects.get(url=url).refresh()
    except socket.error, exc:
        refresh_feed.retry(exc=exc)

Calling the resulting task:

>>> refresh_feed("http://example.com/rss") # Regular
<Feed: http://example.com/rss>
>>> refresh_feed.delay("http://example.com/rss") # Async
<AsyncResult: 8998d0f4-da0b-4669-ba03-d5ab5ac6ad5d>
celery.task.periodic_task(*args, **options)

Decorator to create a task class out of any callable.

Examples

@task
def refresh_feed(url):
    return Feed.objects.get(url=url).refresh()

With setting extra options and using retry.

from celery.task import current

@task(exchange="feeds")
def refresh_feed(url):
    try:
        return Feed.objects.get(url=url).refresh()
    except socket.error, exc:
        current.retry(exc=exc)

Calling the resulting task:

>>> refresh_feed("http://example.com/rss") # Regular
<Feed: http://example.com/rss>
>>> refresh_feed.delay("http://example.com/rss") # Async
<AsyncResult: 8998d0f4-da0b-4669-ba03-d5ab5ac6ad5d>
class celery.task.Task

Task base class.

When called tasks apply the run() method. This method must be defined by all tasks (that is unless the __call__() method is overridden).

Previous topic

celery.app.defaults

Next topic

celery.task.base

This Page