This document describes Celery 3.0. For development docs, go here.
This is the old task module, it should not be used anymore, import from the main ‘celery’ module instead. If you’re looking for the decorator implementation then that’s in celery.app.base.Celery.task.
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>
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>
Deprecated Task base class.
Modern applications should use celery.Task instead.
See also