Browse Source

Consistently use @task() (with parens) in docs

Ask Solem 12 years ago
parent
commit
4e14f7605e

+ 4 - 4
Changelog

@@ -1416,7 +1416,7 @@ Important Notes
 
                 from celery.decorators import task
 
-                @task
+                @task()
                 def add(x, y, **kwargs):
                     print("In task %s" % kwargs["task_id"])
                     return x + y
@@ -1427,7 +1427,7 @@ Important Notes
 
                 from celery.task import task
 
-                @task
+                @task()
                 def add(x, y):
                     print("In task %s" % add.request.id)
                     return x + y
@@ -1543,7 +1543,7 @@ Important Notes
         from celery.contrib import rdb
         from celery.task import task
 
-        @task
+        @task()
         def add(x, y):
             result = x + y
             rdb.set_trace()  # <- set breakpoint
@@ -4301,7 +4301,7 @@ Backward incompatible changes
 
         from celery.decorators import task
 
-        @task
+        @task()
         def add(x, y):
             return x + y
 

+ 1 - 1
FAQ

@@ -505,7 +505,7 @@ How can I get the task id of the current task?
 
 **Answer**: The current id and more is available in the task request::
 
-    @celery.task
+    @celery.task()
     def mytask():
         cache.set(mytask.request.id, "Running")
 

+ 1 - 1
celery/app/task.py

@@ -537,7 +537,7 @@ class Task(object):
 
         .. code-block:: python
 
-            >>> @task
+            >>> @task()
             >>> def tweet(auth, message):
             ...     twitter = Twitter(oauth=auth)
             ...     try:

+ 3 - 3
celery/contrib/methods.py

@@ -13,7 +13,7 @@ Examples
 
     class X(object):
 
-        @task
+        @task()
         def add(self, x, y):
                 return x + y
 
@@ -42,13 +42,13 @@ Caveats
 
         class A(object):
 
-            @task
+            @task()
             def add(self, x, y):
                 return x + y
 
         class B(object):
 
-            @task
+            @task()
             def add(self, x, y):
                 return x + y
 

+ 2 - 2
celery/contrib/rdb.py

@@ -11,9 +11,9 @@ Inspired by http://snippets.dzone.com/posts/show/7248
 .. code-block:: python
 
     from celery.contrib import rdb
-    from celery.task import task
+    from celery import task
 
-    @task
+    @task()
     def add(x, y):
         result = x + y
         rdb.set_trace()

+ 3 - 3
celery/result.py

@@ -125,15 +125,15 @@ class AsyncResult(ResultBase):
 
         .. code-block:: python
 
-            @task
+            @task()
             def A(how_many):
                 return TaskSet(B.s(i) for i in xrange(how_many))
 
-            @task
+            @task()
             def B(i):
                 return pow2.delay(i)
 
-            @task
+            @task()
             def pow2(i):
                 return i ** 2
 

+ 2 - 2
celery/task/base.py

@@ -162,7 +162,7 @@ def task(*args, **kwargs):
 
     .. code-block:: python
 
-        @task
+        @task()
         def refresh_feed(url):
             return Feed.objects.get(url=url).refresh()
 
@@ -195,7 +195,7 @@ def periodic_task(*args, **options):
 
             .. code-block:: python
 
-                @task
+                @task()
                 def refresh_feed(url):
                     return Feed.objects.get(url=url).refresh()
 

+ 2 - 2
celery/tests/app/test_annotations.py

@@ -7,12 +7,12 @@ from celery.utils.imports import qualname
 from celery.tests.utils import Case
 
 
-@task
+@task()
 def add(x, y):
     return x + y
 
 
-@task
+@task()
 def mul(x, y):
     return x * y
 

+ 1 - 1
celery/tests/app/test_beat.py

@@ -165,7 +165,7 @@ class test_Scheduler(Case):
 
     def test_apply_async_should_not_sync(self):
 
-        @task
+        @task()
         def not_sync():
             pass
         not_sync.apply_async = Mock()

+ 2 - 2
celery/tests/app/test_builtins.py

@@ -8,12 +8,12 @@ from celery.state import _task_stack
 from celery.tests.utils import Case
 
 
-@task
+@task()
 def add(x, y):
     return x + y
 
 
-@task
+@task()
 def xsum(x):
     return sum(x)
 

+ 1 - 1
celery/tests/app/test_control.py

@@ -12,7 +12,7 @@ from celery.utils import uuid
 from celery.tests.utils import Case
 
 
-@task
+@task()
 def mytask():
     pass
 

+ 1 - 1
celery/tests/app/test_routes.py

@@ -12,7 +12,7 @@ from celery.task import task
 from celery.tests.utils import Case
 
 
-@task
+@task()
 def mytask():
     pass
 

+ 1 - 1
celery/tests/bin/test_celery.py

@@ -28,7 +28,7 @@ from celery.bin.celery import (
 from celery.tests.utils import AppCase, WhateverIO
 
 
-@task
+@task()
 def add(x, y):
     return x + y
 

+ 3 - 3
celery/tests/functional/tasks.py

@@ -5,12 +5,12 @@ import time
 from celery import task, subtask
 
 
-@task
+@task()
 def add(x, y):
     return x + y
 
 
-@task
+@task()
 def add_cb(x, y, callback=None):
     result = x + y
     if callback:
@@ -18,7 +18,7 @@ def add_cb(x, y, callback=None):
     return result
 
 
-@task
+@task()
 def sleeptask(i):
     time.sleep(i)
     return i

+ 3 - 3
celery/tests/tasks/test_canvas.py

@@ -16,17 +16,17 @@ SIG = Signature({"task": "TASK",
                  "subtask_type": ""})
 
 
-@task
+@task()
 def add(x, y):
     return x + y
 
 
-@task
+@task()
 def mul(x, y):
     return x * y
 
 
-@task
+@task()
 def div(x, y):
     return x / y
 

+ 3 - 3
celery/tests/tasks/test_chord.py

@@ -56,7 +56,7 @@ class test_unlock_chord_task(AppCase):
             is_ready = True
             value = [2, 4, 8, 6]
 
-        @task
+        @task()
         def callback(*args, **kwargs):
             pass
 
@@ -104,11 +104,11 @@ class test_chord(AppCase):
     def test_eager(self):
         from celery import chord
 
-        @task
+        @task()
         def addX(x, y):
             return x + y
 
-        @task
+        @task()
         def sumX(n):
             return sum(n)
 

+ 1 - 1
celery/tests/tasks/test_result.py

@@ -24,7 +24,7 @@ from celery.tests.utils import AppCase
 from celery.tests.utils import skip_if_quick
 
 
-@task
+@task()
 def mytask():
     pass
 

+ 1 - 1
docs/configuration.rst

@@ -1043,7 +1043,7 @@ Example:
 
     from celery.exceptions import SoftTimeLimitExceeded
 
-    @celery.task
+    @celery.task()
     def mytask():
         try:
             return do_work()

+ 1 - 1
docs/django/first-steps-with-django.rst

@@ -74,7 +74,7 @@ a new file called ``celerytest/tasks.py``:
 
     from celery import task
 
-    @task
+    @task()
     def add(x, y):
         return x + y
 

+ 1 - 1
docs/getting-started/first-steps-with-celery.rst

@@ -110,7 +110,7 @@ Let's create the file :file:`tasks.py`:
 
     celery = Celery("tasks", broker="amqp://guest@localhost//")
 
-    @celery.task
+    @celery.task()
     def add(x, y):
         return x + y
 

+ 3 - 3
docs/getting-started/next-steps.rst

@@ -248,7 +248,7 @@ is the same as having a task doing:
 
 .. code-block:: python
 
-    @celery.task
+    @celery.task()
     def temp():
         return [xsum(range(10)), xsum(range(100))]
 
@@ -261,7 +261,7 @@ is the same as having a task doing:
 
 .. code-block:: python
 
-    @celery.task
+    @celery.task()
     def temp():
         return [add(i, i) for i in range(10)]
 
@@ -388,7 +388,7 @@ the error callbacks take the id of the parent task as argument instead:
 
     from proj.celery import celery
 
-    @celery.task
+    @celery.task()
     def log_error(task_id):
         result = celery.AsyncResult(task_id)
         result.get(propagate=False)  # make sure result written.

+ 1 - 1
docs/includes/introduction.txt

@@ -110,7 +110,7 @@ adding two numbers:
 
     from celery import task
 
-    @task
+    @task()
     def add(x, y):
         return x + y
 

+ 2 - 2
docs/internals/deprecation.rst

@@ -79,7 +79,7 @@ for example::
 
     from celery.decorators import task
 
-    @task
+    @task()
     def add(x, y, task_id=None):
         print("My task id is %r" % (task_id, ))
 
@@ -87,7 +87,7 @@ must be rewritten into::
 
     from celery import task
 
-    @task
+    @task()
     def add(x, y):
         print("My task id is %r" % (add.request.id, ))
 

+ 2 - 2
docs/internals/guide.rst

@@ -191,7 +191,7 @@ Here's an example using Celery in single-mode:
 
     from .models import CeleryStats
 
-    @task
+    @task()
     def write_stats_to_db():
         stats = inspect().stats(timeout=1)
         for node_name, reply in stats:
@@ -205,7 +205,7 @@ and here's the same using Celery app objects:
     from .celery import celery
     from .models import CeleryStats
 
-    @celery.task
+    @celery.task()
     def write_stats_to_db():
         stats = celery.control.inspect().stats(timeout=1)
         for node_name, reply in stats:

+ 2 - 2
docs/reference/celery.rst

@@ -132,7 +132,7 @@ Application
 
         .. code-block:: python
 
-            @task
+            @celery.task()
             def refresh_feed(url):
                 return ...
 
@@ -140,7 +140,7 @@ Application
 
         .. code-block:: python
 
-            @task(exchange="feeds")
+            @celery.task(exchange="feeds")
             def refresh_feed(url):
                 return ...
 

+ 1 - 1
docs/tutorials/debugging.rst

@@ -18,7 +18,7 @@ Example usage:
     from celery import task
     from celery.contrib import rdb
 
-    @task
+    @task()
     def add(x, y):
         result = x + y
         rdb.set_trace()  # <- set breakpoint

+ 1 - 1
docs/userguide/executing.rst

@@ -41,7 +41,7 @@ called `add`, returning the sum of two positional arguments:
 
 .. code-block:: python
 
-    @celery.task
+    @celery.task()
     def add(x, y):
         return x + y
 

+ 2 - 2
docs/userguide/groups.rst

@@ -186,11 +186,11 @@ already a standard function):
 
 .. code-block:: python
 
-    @celery.task
+    @celery.task()
     def add(x, y):
         return x + y
 
-    @celery.task
+    @celery.task()
     def tsum(numbers):
         return sum(numbers)
 

+ 17 - 17
docs/userguide/tasks.rst

@@ -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)

+ 1 - 1
docs/userguide/workers.rst

@@ -158,7 +158,7 @@ time limit kills it:
     from myapp import celery
     from celery.exceptions import SoftTimeLimitExceeded
 
-    @celery.task
+    @celery.task()
     def mytask():
         try:
             do_work()

+ 1 - 1
docs/whatsnew-2.6.rst

@@ -125,7 +125,7 @@ Tasks can now have callbacks and errbacks, and dependencies are recorded
 
         .. code-block:: python
 
-            @task
+            @celery.task()
             def error_handler(uuid):
                 result = AsyncResult(uuid)
                 exc = result.get(propagate=False)

+ 1 - 1
examples/celery_http_gateway/tasks.py

@@ -1,6 +1,6 @@
 from celery.task import task
 
 
-@task
+@task()
 def hello_world(to="world"):
     return "Hello %s" % to

+ 1 - 1
examples/eventlet/tasks.py

@@ -2,7 +2,7 @@ from celery.task import task
 from eventlet.green import urllib2
 
 
-@task
+@task()
 def urlopen(url):
     print("Opening: %r" % (url, ))
     try:

+ 3 - 3
examples/next-steps/proj/tasks.py

@@ -3,16 +3,16 @@ from __future__ import absolute_import
 from proj.celery import celery
 
 
-@celery.task
+@celery.task()
 def add(x, y):
     return x + y
 
 
-@celery.task
+@celery.task()
 def mul(x, y):
     return x * y
 
 
-@celery.task
+@celery.task()
 def xsum(numbers):
     return sum(numbers)

+ 7 - 7
examples/resultgraph/tasks.py

@@ -23,30 +23,30 @@ from celery.task import chord, subtask, task, TaskSet
 from celery.result import AsyncResult, ResultSet
 from collections import deque
 
-@task
+@task()
 def add(x, y):
     return x + y
 
 
-@task
+@task()
 def make_request(id, url):
     print("GET %r" % (url, ))
     return url
 
 
-@task
+@task()
 def B_callback(urls, id):
     print("batch %s done" % (id, ))
     return urls
 
 
-@task
+@task()
 def B(id):
     return chord(make_request.subtask((id, "%s %r" % (id, i, )))
                     for i in xrange(10))(B_callback.subtask((id, )))
 
 
-@task
+@task()
 def A():
     return TaskSet(B.subtask((c, )) for c in "ABCDEFGH").apply_async()
 
@@ -70,7 +70,7 @@ def joinall(R, timeout=None, propagate=True):
             yield res
 
 
-@task
+@task()
 def unlock_graph(result, callback, interval=1, propagate=False,
         max_retries=None):
     if result.ready():
@@ -82,7 +82,7 @@ def unlock_graph(result, callback, interval=1, propagate=False,
         unlock_graph.retry(countdown=interval, max_retries=max_retries)
 
 
-@task
+@task()
 def A_callback(res):
     print("Everything is done: %r" % (res, ))
     return res

+ 1 - 1
examples/tutorial/tasks.py

@@ -4,7 +4,7 @@ from celery import Celery
 
 celery = Celery("tasks", broker="amqp://")
 
-@celery.task
+@celery.task()
 def add(x, y):
     return x + y