Sfoglia il codice sorgente

celery.task.task example used magic kwargs

Ask Solem 14 anni fa
parent
commit
1086f7bda2
1 ha cambiato i file con 14 aggiunte e 14 eliminazioni
  1. 14 14
      celery/task/__init__.py

+ 14 - 14
celery/task/__init__.py

@@ -12,26 +12,26 @@ __all__ = ["Task", "TaskSet", "PeriodicTask", "subtask", "discard_all"]
 def task(*args, **kwargs):
     """Decorator to create a task class out of any callable.
 
-    .. admonition:: Examples
+    **Examples**
 
-        .. code-block:: python
+    .. code-block:: python
 
-            @task()
-            def refresh_feed(url):
-                return Feed.objects.get(url=url).refresh()
+        @task()
+        def refresh_feed(url):
+            return Feed.objects.get(url=url).refresh()
 
-        With setting extra options and using retry.
+    With setting extra options and using retry.
 
-        .. code-block:: python
+    .. code-block:: python
 
-            @task(exchange="feeds")
-            def refresh_feed(url, **kwargs):
-                try:
-                    return Feed.objects.get(url=url).refresh()
-                except socket.error, exc:
-                    refresh_feed.retry(args=[url], kwargs=kwargs, exc=exc)
+        @task(max_retries=10)
+        def refresh_feed(url):
+            try:
+                return Feed.objects.get(url=url).refresh()
+            except socket.error, exc:
+                refresh_feed.retry(exc=exc)
 
-        Calling the resulting task:
+    Calling the resulting task:
 
             >>> refresh_feed("http://example.com/rss") # Regular
             <Feed: http://example.com/rss>