|
@@ -21,7 +21,7 @@ the task decorator:
|
|
|
|
|
|
from django.contrib.auth import User
|
|
|
|
|
|
- @celery.task
|
|
|
+ @celery.task()
|
|
|
def create_user(username, password):
|
|
|
User.objects.create(username=username, password=password)
|
|
|
|
|
@@ -43,7 +43,7 @@ Task options can be specified as arguments to the decorator:
|
|
|
|
|
|
from celery import task
|
|
|
|
|
|
- @task
|
|
|
+ @task()
|
|
|
def add(x, y):
|
|
|
return x + y
|
|
|
|
|
@@ -87,7 +87,7 @@ Example Usage
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
- @celery.task
|
|
|
+ @celery.task()
|
|
|
def add(x, y):
|
|
|
print("Executing task id %r, args: %r kwargs: %r" % (
|
|
|
add.request.id, add.request.args, add.request.kwargs))
|
|
@@ -103,7 +103,7 @@ logger that can be used freely to emit logs from your tasks.
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
- @celery.task
|
|
|
+ @celery.task()
|
|
|
def add(x, y):
|
|
|
logger = add.get_logger()
|
|
|
logger.info("Adding %s + %s" % (x, y))
|
|
@@ -127,7 +127,7 @@ of temporary failure.
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
- @celery.task
|
|
|
+ @celery.task()
|
|
|
def send_twitter_status(oauth, tweet):
|
|
|
try:
|
|
|
twitter = Twitter(oauth)
|
|
@@ -407,7 +407,7 @@ task if the module name is "tasks.py":
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
- >>> @celery.task
|
|
|
+ >>> @celery.task()
|
|
|
>>> def add(x, y):
|
|
|
... return x + y
|
|
|
|
|
@@ -461,7 +461,7 @@ decorator is applied last:
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
- @celery.task
|
|
|
+ @celery.task()
|
|
|
@decorator2
|
|
|
@decorator1
|
|
|
def add(x, y):
|
|
@@ -647,7 +647,7 @@ which defines its own custom :state:`ABORTED` state.
|
|
|
|
|
|
Use :meth:`~@Task.update_state` to update a task's state::
|
|
|
|
|
|
- @celery.task
|
|
|
+ @celery.task()
|
|
|
def upload_files(filenames):
|
|
|
for i, file in enumerate(filenames):
|
|
|
upload_files.update_state(state="PROGRESS",
|
|
@@ -729,7 +729,7 @@ As an example, the following code,
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
- @celery.task
|
|
|
+ @celery.task()
|
|
|
def add(x, y):
|
|
|
return x + y
|
|
|
|
|
@@ -738,7 +738,7 @@ will do roughly this behind the scenes:
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
- @celery.task
|
|
|
+ @celery.task()
|
|
|
class AddTask(Task):
|
|
|
|
|
|
def run(self, x, y):
|
|
@@ -980,21 +980,21 @@ Make your design asynchronous instead, for example by using *callbacks*.
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
- @celery.task
|
|
|
+ @celery.task()
|
|
|
def update_page_info(url):
|
|
|
page = fetch_page.delay(url).get()
|
|
|
info = parse_page.delay(url, page).get()
|
|
|
store_page_info.delay(url, info)
|
|
|
|
|
|
- @celery.task
|
|
|
+ @celery.task()
|
|
|
def fetch_page(url):
|
|
|
return myhttplib.get(url)
|
|
|
|
|
|
- @celery.task
|
|
|
+ @celery.task()
|
|
|
def parse_page(url, page):
|
|
|
return myparser.parse_document(page)
|
|
|
|
|
|
- @celery.task
|
|
|
+ @celery.task()
|
|
|
def store_page_info(url, info):
|
|
|
return PageInfo.objects.create(url, info)
|
|
|
|
|
@@ -1124,7 +1124,7 @@ that automatically expands some abbreviations in it:
|
|
|
title = models.CharField()
|
|
|
body = models.TextField()
|
|
|
|
|
|
- @celery.task
|
|
|
+ @celery.task()
|
|
|
def expand_abbreviations(article):
|
|
|
article.body.replace("MyCorp", "My Corporation")
|
|
|
article.save()
|
|
@@ -1145,7 +1145,7 @@ re-fetch the article in the task body:
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
- @celery.task
|
|
|
+ @celery.task()
|
|
|
def expand_abbreviations(article_id):
|
|
|
article = Article.objects.get(id=article_id)
|
|
|
article.body.replace("MyCorp", "My Corporation")
|
|
@@ -1304,7 +1304,7 @@ blog/tasks.py
|
|
|
from blog.models import Comment
|
|
|
|
|
|
|
|
|
- @celery.task
|
|
|
+ @celery.task()
|
|
|
def spam_filter(comment_id, remote_addr=None):
|
|
|
logger = spam_filter.get_logger()
|
|
|
logger.info("Running spam filter for comment %s" % comment_id)
|