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

celery.task

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.

@task(exchange="feeds")
def refresh_feed(url, **kwargs):
    try:
        return Feed.objects.get(url=url).refresh()
    except socket.error, exc:
        refresh_feed.retry(args=[url], kwargs=kwargs, 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.result

Next topic

celery.task.control

This Page