Browse Source

Revert task decorators to no empty parents, as it just looks so much worse

Ask Solem 12 years ago
parent
commit
6cd6f29b30

+ 1 - 1
docs/configuration.rst

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

+ 3 - 3
docs/faq.rst

@@ -627,7 +627,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")
 
@@ -673,7 +673,7 @@ Also, a common pattern is to add callbacks to tasks:
 
     logger = get_task_logger(__name__)
 
-    @celery.task()
+    @celery.task
     def add(x, y):
         return x + y
 
@@ -787,7 +787,7 @@ this is rarely the case. Imagine the following task:
 
 .. code-block:: python
 
-    @celery.task()
+    @celery.task
     def process_upload(filename, tmpfile):
         # Increment a file count stored in a database
         increment_file_counter()

+ 1 - 1
docs/getting-started/introduction.rst

@@ -88,7 +88,7 @@ Celery is…
 
             celery = Celery('hello', broker='amqp://guest@localhost//')
 
-            @celery.task()
+            @celery.task
             def hello():
                 return 'hello world'
 

+ 1 - 1
docs/includes/introduction.txt

@@ -91,7 +91,7 @@ Celery is...
 
         celery = Celery('hello', broker='amqp://guest@localhost//')
 
-        @celery.task()
+        @celery.task
         def hello():
             return 'hello world'
 

+ 1 - 1
docs/internals/app-overview.rst

@@ -25,7 +25,7 @@ Creating tasks:
 
 .. code-block:: python
 
-    @celery.task()
+    @celery.task
     def add(x, y):
         return x + y
 

+ 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:

+ 1 - 1
docs/reference/celery.rst

@@ -145,7 +145,7 @@ Application
 
         .. code-block:: python
 
-            @celery.task()
+            @celery.task
             def refresh_feed(url):
                 return ...
 

+ 5 - 5
docs/userguide/application.rst

@@ -45,7 +45,7 @@ Whenever you define a task, that task will also be added to the local registry:
 
 .. code-block:: python
 
-    >>> @celery.task()
+    >>> @celery.task
     ... def add(x, y):
     ...     return x + y
 
@@ -76,7 +76,7 @@ For example here, where the tasks module is also used to start a worker:
     from celery import Celery
     celery = Celery()
 
-    @celery.task()
+    @celery.task
     def add(x, y): return x + y
 
     if __name__ == '__main__':
@@ -98,7 +98,7 @@ You can specify another name for the main module:
     >>> celery.main
     'tasks'
 
-    >>> @celery.task()
+    >>> @celery.task
     ... def add(x, y):
     ...     return x + y
 
@@ -258,7 +258,7 @@ we use the task, or access an attribute (in this case :meth:`repr`):
 
 .. code-block:: python
 
-    >>> @celery.task()
+    >>> @celery.task
     >>> def add(x, y):
     ...    return x + y
 
@@ -472,7 +472,7 @@ by changing its :meth:`@Celery.Task` attribute:
     >>> celery.Task
     <unbound MyBaseTask>
 
-    >>> @x.task()
+    >>> @x.task
     ... def add(x, y):
     ...     return x + y
 

+ 2 - 2
docs/userguide/calling.rst

@@ -87,7 +87,7 @@ called `add`, returning the sum of two arguments:
 
 .. code-block:: python
 
-    @celery.task()
+    @celery.task
     def add(x, y):
         return x + y
 
@@ -144,7 +144,7 @@ This is an example error callback:
 
 .. code-block:: python
 
-    @celery.task()
+    @celery.task
     def error_handler(uuid):
         result = AsyncResult(uuid)
         exc = result.get(propagate=False)

+ 5 - 5
docs/userguide/canvas.rst

@@ -459,7 +459,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.
@@ -676,11 +676,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)
 
@@ -789,7 +789,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))]
 
@@ -802,7 +802,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)]
 

+ 18 - 18
docs/userguide/tasks.rst

@@ -53,7 +53,7 @@ the :meth:`~@Celery.task` decorator:
 
     from .models import User
 
-    @celery.task()
+    @celery.task
     def create_user(username, password):
         User.objects.create(username=username, password=password)
 
@@ -79,7 +79,7 @@ these can be specified as arguments to the decorator:
 
         from celery import task
 
-        @task()
+        @task
         def add(x, y):
             return x + y
 
@@ -92,7 +92,7 @@ these can be specified as arguments to the decorator:
 
     .. code-block:: python
 
-        @celery.task()
+        @celery.task
         @decorator2
         @decorator1
         def add(x, y):
@@ -139,7 +139,7 @@ if the module name is "tasks.py":
 
 .. code-block:: python
 
-    @celery.task()
+    @celery.task
     def add(x, y):
         return x + y
 
@@ -227,7 +227,7 @@ An example task accessing information in the context is:
 
 .. 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))
@@ -240,7 +240,7 @@ An example task accessing information in the context is:
 
     from celery import current_task
 
-    @celery.task()
+    @celery.task
     def add(x, y):
         request = current_task.request
         print('Executing task id %r, args: %r kwargs: %r' % (
@@ -268,7 +268,7 @@ for all of your tasks at the top of your module:
 
     logger = get_task_logger(__name__)
 
-    @celery.task()
+    @celery.task
     def add(x, y):
         logger.info('Adding %s + %s' % (x, y))
         return x + y
@@ -301,7 +301,7 @@ Here's an example using ``retry``:
 
 .. code-block:: python
 
-    @celery.task()
+    @celery.task
     def send_twitter_status(oauth, tweet):
         try:
             twitter = Twitter(oauth)
@@ -685,7 +685,7 @@ Use :meth:`~@Task.update_state` to update a task's state::
 
     from celery import current_task
 
-    @celery.task()
+    @celery.task
     def upload_files(filenames):
         for i, file in enumerate(filenames):
             current_task.update_state(state='PROGRESS',
@@ -767,7 +767,7 @@ As an example, the following code,
 
 .. code-block:: python
 
-    @celery.task()
+    @celery.task
     def add(x, y):
         return x + y
 
@@ -776,7 +776,7 @@ will do roughly this behind the scenes:
 
 .. code-block:: python
 
-    @celery.task()
+    @celery.task
     class AddTask(Task):
 
         def run(self, x, y):
@@ -1016,21 +1016,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)
 
@@ -1147,7 +1147,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()
@@ -1168,7 +1168,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')
@@ -1329,7 +1329,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

@@ -293,7 +293,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-3.0.rst

@@ -581,7 +581,7 @@ Logging support now conforms better with best practices.
 
         logger = get_task_logger(__name__)
 
-        @celery.task()
+        @celery.task
         def add(x, y):
             logger.debug('Adding %r + %r' % (x, y))
             return x + y