Преглед изворни кода

HTTP gateway example used removed celery.ping task

Ask Solem пре 13 година
родитељ
комит
c8479b7aec

+ 8 - 6
celery/app/__init__.py

@@ -153,12 +153,14 @@ class App(base.BaseApp):
 
             .. 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)
+            from celery.task import current
+
+            @task(exchange="feeds")
+            def refresh_feed(url):
+                try:
+                    return Feed.objects.get(url=url).refresh()
+                except socket.error, exc:
+                    current.retry(exc=exc)
 
             Calling the resulting task:
 

+ 3 - 1
celery/task/__init__.py

@@ -70,12 +70,14 @@ def periodic_task(*args, **options):
 
             .. code-block:: python
 
+                from celery.task import current
+
                 @task(exchange="feeds")
                 def refresh_feed(url):
                     try:
                         return Feed.objects.get(url=url).refresh()
                     except socket.error, exc:
-                        refresh_feed.retry(exc=exc)
+                        current.retry(exc=exc)
 
             Calling the resulting task:
 

+ 6 - 0
examples/celery_http_gateway/tasks.py

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

+ 3 - 2
examples/celery_http_gateway/urls.py

@@ -1,15 +1,16 @@
 from django.conf.urls.defaults import *
 
-from celery.task import PingTask
 from djcelery import views as celery_views
 
+from celery_http_gateway.tasks import hello_world
+
 # Uncomment the next two lines to enable the admin:
 # from django.contrib import admin
 # admin.autodiscover()
 
 urlpatterns = patterns("",
     url(r'^apply/(?P<task_name>.+?)/', celery_views.apply),
-    url(r'^ping/', celery_views.task_view(PingTask)),
+    url(r'^hello/', celery_views.task_view(hello_world)),
     url(r'^(?P<task_id>[\w\d\-]+)/done/?$', celery_views.is_task_successful,
         name="celery-is_task_successful"),
     url(r'^(?P<task_id>[\w\d\-]+)/status/?$', celery_views.task_status,