瀏覽代碼

Moved docs from cookbook into userguide

Ask Solem 15 年之前
父節點
當前提交
61e1077fe3
共有 6 個文件被更改,包括 58 次插入61 次删除
  1. 3 3
      FAQ
  2. 0 2
      docs/cookbook/index.rst
  3. 0 54
      docs/cookbook/task-retries.rst
  4. 1 0
      docs/userguide/index.rst
  5. 2 1
      docs/userguide/remote-tasks.rst
  6. 52 1
      docs/userguide/tasks.rst

+ 3 - 3
FAQ

@@ -61,10 +61,10 @@ messages. There's no other communication involved.
 Also, there's another way to be language indepedent, and that is to use REST
 tasks, instead of your tasks being functions, they're URLs. With this
 information you can even create simple web servers that enable preloading of
-code. For more information about REST tasks see: `Cookbook: Remote Tasks`_.
+code. For more information about REST tasks see: `User Guide: Remote Tasks`_.
 
-.. _`Cookbook: Remote Tasks`:
-    http://ask.github.com/celery/cookbook/remote-tasks.html
+.. _`User Guide: Remote Tasks`:
+    http://ask.github.com/celery/userguide/remote-tasks.html
 
 
 Troubleshooting

+ 0 - 2
docs/cookbook/index.rst

@@ -6,8 +6,6 @@
     :maxdepth: 2
 
     tasks
-    task-retries
-    remote-tasks
     unit-testing
 
 This page contains common recipes and techniques.

+ 0 - 54
docs/cookbook/task-retries.rst

@@ -1,54 +0,0 @@
-================
- Retrying Tasks
-================
-
-
-Retrying a task if something fails
-==================================
-
-Simply use :meth:`celery.task.base.Task.retry` to re-sent the task, it will
-do the right thing, and respect the :attr:`celery.task.base.Task.max_retries`
-attribute:
-
-.. code-block:: python
-
-    class SendTwitterStatusTask(Task):
-    
-        def run(self, oauth, tweet, **kwargs):
-            try:
-                twitter = Twitter(oauth)
-                twitter.update_status(tweet)
-            except (Twitter.FailWhaleError, Twitter.LoginError), exc:
-                self.retry(args=[oauth, tweet], exc=exc, **kwargs)
-
-Here we used the ``exc`` argument to pass the current exception to
-:meth:`celery.task.base.Task.retry`. At each step of the retry this exception
-is available as the tombstone (result) of the task, when
-:attr:`celery.task.base.Task.max_retries` has been exceeded this is the exception
-raised. However, if an ``exc`` argument is not provided the
-:exc:`celery.task.base.RetryTaskError` exception is raised instead.
-  
-Setting a custom delay for retries.
-===================================
-
-The default countdown is in the tasks
-:attr:`celery.task.base.Task.default_retry_delay` attribute, which by
-default is set to 3 minutes.
-
-You can also provide the ``countdown`` argument to
-:meth:`celery.task.base.Task.retry` to override this default.
-
-.. code-block:: python
-
-    class MyTask(Task):
-        default_retry_delay = 30 * 60 # retry in 30 minutes
-
-        def run(self, x, y, **kwargs):
-            try:
-                ...
-            except Exception, exc:
-                self.retry([x, y], exc=exc,
-                           countdown=60 # override the default and
-                                        # retry in 1 minute
-                           **kwargs)
-

+ 1 - 0
docs/userguide/index.rst

@@ -10,3 +10,4 @@
 
     tasks
     executing
+    remote-tasks

+ 2 - 1
docs/cookbook/remote-tasks.rst → docs/userguide/remote-tasks.rst

@@ -2,6 +2,7 @@
  Remote Tasks 
 ==============
 
+.. module:: celery.task.rest
 
 Executing tasks on a remote web server
 --------------------------------------
@@ -42,7 +43,7 @@ With this information we can define a simple task in Django:
 I'm sure you'll be able to port this scheme to any language/framework.
 New examples and libraries are very welcome!
 
-To execute the task you use :class:`celery.task.rest.RESTProxyTask`:
+To execute the task you use :class:`RESTProxyTask`:
 
     >>> from celery.task import RESTProxyTask
     >>> res = RESTProxyTask.delay("http://example.com/multiply", x=10, y=10)

+ 52 - 1
docs/userguide/tasks.rst

@@ -2,6 +2,8 @@
  Tasks
 =======
 
+.. module:: celery.task.base
+
 A task is a class that encapsulates a function and its execution options.
 With a function ``create_user``, that takes two arguments: ``username`` and
 ``password``, you can create a task like this:
@@ -103,6 +105,55 @@ or using the decorator syntax:
 There are several logging levels available, and the workers ``loglevel``
 setting decides whether they will be sent to the log file or not.
 
+Retrying a task if something fails
+==================================
+
+Simply use :meth:`Task.retry` to re-sent the task, it will
+do the right thing, and respect the :attr:`Task.max_retries`
+attribute:
+
+.. code-block:: python
+
+    @task()
+    def send_twitter_status(oauth, tweet, **kwargs):
+        try:
+            twitter = Twitter(oauth)
+            twitter.update_status(tweet)
+        except (Twitter.FailWhaleError, Twitter.LoginError), exc:
+            send_twitter_status.retry(args=[oauth, tweet], exc=exc, **kwargs)
+
+Here we used the ``exc`` argument to pass the current exception to
+:meth:`Task.retry`. At each step of the retry this exception
+is available as the tombstone (result) of the task, when
+:attr:`Task.max_retries` has been exceeded this is the exception
+raised. However, if an ``exc`` argument is not provided the
+:exc:`RetryTaskError` exception is raised instead.
+
+Using a custom retry delay
+--------------------------
+
+The default countdown is in the tasks
+:attr:`Task.default_retry_delay` attribute, which by
+default is set to 3 minutes.
+
+You can also provide the ``countdown`` argument to
+:meth:`Task.retry` to override this default.
+
+.. code-block:: python
+
+    class MyTask(Task):
+        default_retry_delay = 30 * 60 # retry in 30 minutes
+
+        def run(self, x, y, **kwargs):
+            try:
+                ...
+            except Exception, exc:
+                self.retry([x, y], exc=exc,
+                           countdown=60 # override the default and
+                                        # retry in 1 minute
+                           **kwargs)
+
+
 
 Task options
 ============
@@ -226,7 +277,7 @@ for the applications listed in ``INSTALLED_APPS``. If you want to do something
 special you can create your own loader to do what you want.
 
 The entity responsible for registering your task in the registry is a
-metaclass, ``celery.task.base.TaskType``, this is the default metaclass for
+metaclass, :class:`TaskType`, this is the default metaclass for
 ``Task``. If you want to register your task manually you can set the
 ``abstract`` attribute: