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

Task Decorators - celery.decorators



Task decorator to create a periodic task.

Example task, scheduling a task once every day:

from datetime import timedelta

def cronjob(**kwargs):
    logger = cronjob.get_logger(**kwargs)
    logger.warn("Task running...")
celery.decorators.task(*args, **options)

Decorator to create a task class out of any callable.


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

With setting extra options and using retry.

def refresh_feed(url, **kwargs):
        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("") # Regular
>>> refresh_feed.delay("") # Async
<AsyncResult: 8998d0f4-da0b-4669-ba03-d5ab5ac6ad5d>

Previous topic

API Reference

Next topic

Defining Tasks - celery.task.base

This Page