From a03817ae38f43be2b4b7bf1e20a46a94c47a3523 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Fri, 25 Jun 2010 13:53:57 +0200 Subject: [PATCH] use celery --- README | 4 ++-- ...ora-encoder.conf => pandora-encoding.conf} | 6 ++--- ...ackgroundtasks.conf => pandora-tasks.conf} | 6 ++--- .../management/commands/backgroundtasks.py | 22 ------------------- pandora/backend/views.py | 4 ++-- .../bin/{pandora-encoder => pandora-encoding} | 2 +- .../{pandora-backgroundtasks => pandora-task} | 2 +- pandora/settings.py | 4 +++- requirements.txt | 3 ++- 9 files changed, 17 insertions(+), 36 deletions(-) rename etc/init/{pandora-encoder.conf => pandora-encoding.conf} (64%) rename etc/init/{pandora-backgroundtasks.conf => pandora-tasks.conf} (61%) delete mode 100644 pandora/backend/management/commands/backgroundtasks.py rename pandora/bin/{pandora-encoder => pandora-encoding} (88%) rename pandora/bin/{pandora-backgroundtasks => pandora-task} (88%) diff --git a/README b/README index 7598514..905b807 100644 --- a/README +++ b/README @@ -19,9 +19,9 @@ installed via apt-get/pip/easy_install in your system path. Install rabbitmq and carrot: sudo apt-get install rabbitmq-server - sudo rabbitmqctl add_user pandora password + sudo rabbitmqctl add_user pandora box sudo rabbitmqctl add_vhost /pandora - sudo rabbitmqctl set_permissions -p /pandora pandora "^pandora-.*" ".*" ".*" + sudo rabbitmqctl set_permissions -p /pandora pandora ".*" ".*" ".*" update BROKER_* settings in local_settings.py: diff --git a/etc/init/pandora-encoder.conf b/etc/init/pandora-encoding.conf similarity index 64% rename from etc/init/pandora-encoder.conf rename to etc/init/pandora-encoding.conf index 61d2ccd..1c093f0 100644 --- a/etc/init/pandora-encoder.conf +++ b/etc/init/pandora-encoding.conf @@ -1,7 +1,7 @@ -# pandora background server +# pandora encoding daemon # -description "pandora background server" +description "pandora encoding daemon" start on runlevel [2345] stop on runlevel [!2345] @@ -10,5 +10,5 @@ respawn chdir /srv/pandora/pandora -exec /bin/su pandora -s /usr/bin/python2.6 /srv/pandora/pandora/bin/pandora-encoder +exec /bin/su pandora -s /usr/bin/python2.6 /srv/pandora/pandora/bin/pandora-encoding diff --git a/etc/init/pandora-backgroundtasks.conf b/etc/init/pandora-tasks.conf similarity index 61% rename from etc/init/pandora-backgroundtasks.conf rename to etc/init/pandora-tasks.conf index cc2955d..2533117 100644 --- a/etc/init/pandora-backgroundtasks.conf +++ b/etc/init/pandora-tasks.conf @@ -1,7 +1,7 @@ -# pandora background server +# pandora background tasks daemon # -description "pandora background server" +description "pandora background tasks daemon" start on runlevel [2345] stop on runlevel [!2345] @@ -10,5 +10,5 @@ respawn chdir /srv/pandora/pandora -exec /bin/su pandora -s /usr/bin/python2.6 /srv/pandora/pandora/bin/pandora-backgroundtasks +exec /bin/su pandora -s /usr/bin/python2.6 /srv/pandora/pandora/bin/pandora-tasks diff --git a/pandora/backend/management/commands/backgroundtasks.py b/pandora/backend/management/commands/backgroundtasks.py deleted file mode 100644 index 7f48849..0000000 --- a/pandora/backend/management/commands/backgroundtasks.py +++ /dev/null @@ -1,22 +0,0 @@ -# -*- coding: utf-8 -*- -# vi:si:et:sw=4:sts=4:ts=4 - -import os -from os.path import join, dirname, basename, splitext, exists - -from django.core.management.base import BaseCommand, CommandError -from django.conf import settings - -from ... import daemon - - -class Command(BaseCommand): - """ - listen to rabbitmq and execute background task. - """ - help = 'listen to rabbitmq and execute background task.' - args = '' - - def handle(self, **options): - daemon.run() - diff --git a/pandora/backend/views.py b/pandora/backend/views.py index 7db4ac7..5298a07 100644 --- a/pandora/backend/views.py +++ b/pandora/backend/views.py @@ -29,7 +29,7 @@ import oxlib import models import utils -from daemon import send_bg_message +import tasks from oxuser.models import getUserJSON from oxuser.views import api_login, api_logout, api_register, api_contact, api_recover, api_preferences @@ -477,7 +477,7 @@ def api_update(request): f = models.ArchiveFile.get_or_create(archive, oshash) f.update(data) if not f.file.movie: - send_bg_message({'findMovie': f.file.id}) + task.findMovie(f.file.id) #FIXME: only add if it was not in File else: f = q[0] diff --git a/pandora/bin/pandora-encoder b/pandora/bin/pandora-encoding similarity index 88% rename from pandora/bin/pandora-encoder rename to pandora/bin/pandora-encoding index efd91dc..09a5d52 100755 --- a/pandora/bin/pandora-encoder +++ b/pandora/bin/pandora-encoding @@ -17,5 +17,5 @@ sys.path.append(os.path.join(root_dir, project_module)) from django.core.management import execute_manager import settings -execute_manager(settings, ['pandora-encoder', 'encoder']) +execute_manager(settings, ['celeryd', 'celeryd', '-Q' 'encoding']) diff --git a/pandora/bin/pandora-backgroundtasks b/pandora/bin/pandora-task similarity index 88% rename from pandora/bin/pandora-backgroundtasks rename to pandora/bin/pandora-task index 2041410..d7738f5 100755 --- a/pandora/bin/pandora-backgroundtasks +++ b/pandora/bin/pandora-task @@ -17,5 +17,5 @@ sys.path.append(os.path.join(root_dir, project_module)) from django.core.management import execute_manager import settings -execute_manager(settings, ['backgroundtasks', 'backgroundtasks']) +execute_manager(settings, ['celeryd', 'celeryd', '-Q' 'default']) diff --git a/pandora/settings.py b/pandora/settings.py index 7179038..54a4821 100644 --- a/pandora/settings.py +++ b/pandora/settings.py @@ -5,7 +5,7 @@ import os from os.path import join SITENAME = 'Pandora' -URL = 'pandora.Oxdb.org' +URL = 'pan.do/ra' PROJECT_ROOT = os.path.normpath(os.path.dirname(__file__)) @@ -33,6 +33,7 @@ DATABASE_PORT = '' # Set to empty string for default. Not used with #CACHE_BACKEND = 'memcached://127.0.0.1:11211/' #rabbitmq connection settings +CELERY_RESULT_BACKEND = "database" BROKER_HOST = "127.0.0.1" BROKER_PORT = 5672 BROKER_USER = "pandora" @@ -106,6 +107,7 @@ INSTALLED_APPS = ( 'django_extensions', 'devserver', # 'south', + 'djcelery', 'app', 'backend', diff --git a/requirements.txt b/requirements.txt index 82d1888..18c97f9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,7 +7,8 @@ chardet simplejson -e hg+https://django-ajax-filtered-fields.googlecode.com/hg/#egg=django-ajax-filtered-fields #rabbitmq interface -carrot +-e git+git://github.com/ask/celery.git#egg=celery +django-celery django_extensions -e bzr+http://firefogg.org/dev/python-firefogg/#egg=python-firefogg -e git+git://github.com/dcramer/django-devserver#egg=django_devserver