Permalink
Browse files

Example django-celery integration

This currently doesn't do anything unless you use
the shell (see https://gist.github.com/873148) but
it has all of the moving parts and uses Celery's 
immediate mode for development without needing a
running queue.
  • Loading branch information...
1 parent 4f27122 commit 32a7cba6e37d0d16af6ca22d84eb9150dfe4eaf5 @acdha acdha committed Mar 16, 2011
Showing with 33 additions and 0 deletions.
  1. +9 −0 apps/package/tasks.py
  2. +1 −0 deploy/pinax.wsgi
  3. +7 −0 local_settings.py.example
  4. +6 −0 requirements/project.txt
  5. +10 −0 settings.py
@@ -0,0 +1,9 @@
+from celery.decorators import task
+
+from packaginator.apps.package.models import Package
+
+
+@task()
+def fetch_package_metadata(pk):
+ package = Package.objects.get(pk=pk)
+ package.fetch_metadata()
View
@@ -15,6 +15,7 @@ sys.path.insert(0, abspath(join(dirname(__file__), "../../")))
from django.conf import settings
os.environ["DJANGO_SETTINGS_MODULE"] = "djangopackages.settings"
+os.environ["CELERY_LOADER"] = "django"
sys.path.insert(0, join(settings.PROJECT_ROOT, "apps"))
@@ -42,3 +42,10 @@ SECRET_KEY = "CHANGE-THIS-KEY-TO-SOMETHING-ELSE"
if SECRET_KEY == "CHANGE-THIS-KEY-TO-SOMETHING-ELSE":
raise Exception('You must change your SECRET_KEY settings in '
'local_settings.py.')
+
+# See http://celeryproject.org/docs/configuration.html#task-execution-settings
+CELERY_ALWAYS_EAGER = True
+CELERY_EAGER_PROPAGATES_EXCEPTIONS = True
+BROKER_BACKEND = "django"
+
+LOCAL_INSTALLED_APPS += ('djkombu', )
@@ -17,3 +17,9 @@ coverage==3.4
django-coverage==1.1.1
django-flatblocks==0.5.0
feedparser==5.0.1
+
+# Celery dependencies:
+celery==2.2.4
+kombu==1.0.4
+django-celery==2.2.4
+django-kombu==0.9.2
View
@@ -187,6 +187,9 @@
"pinax.apps.account",
"pinax.apps.signup_codes",
"pinax.apps.analytics",
+
+ # Celery task queue:
+ 'djcelery',
]
INSTALLED_APPS = PREREQ_APPS + PROJECT_APPS
@@ -269,6 +272,9 @@
"""
}
+#: See http://ask.github.com/celery/configuration.html
+CELERYD_TASK_TIME_LIMIT = 300
+
LOCAL_INSTALLED_APPS = []
# local_settings.py can be used to override environment-specific settings
@@ -280,3 +286,7 @@
if LOCAL_INSTALLED_APPS:
INSTALLED_APPS.extend(LOCAL_INSTALLED_APPS)
+
+import djcelery
+djcelery.setup_loader()
+

0 comments on commit 32a7cba

Please sign in to comment.