From 207e438e694056233a66738e7825103825673ab4 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Thu, 31 Dec 2009 16:06:26 +0100 Subject: [PATCH] more stuff --- oxdb/backend/daemon.py | 20 +++++++++++++++++ oxdb/backend/management/__init__.py | 0 oxdb/backend/management/commands/__init__.py | 0 .../management/commands/backgroundtasks.py | 22 +++++++++++++++++++ 4 files changed, 42 insertions(+) create mode 100644 oxdb/backend/daemon.py create mode 100644 oxdb/backend/management/__init__.py create mode 100644 oxdb/backend/management/commands/__init__.py create mode 100644 oxdb/backend/management/commands/backgroundtasks.py diff --git a/oxdb/backend/daemon.py b/oxdb/backend/daemon.py new file mode 100644 index 000000000..dd214c2d6 --- /dev/null +++ b/oxdb/backend/daemon.py @@ -0,0 +1,20 @@ +from carrot.connection import DjangoBrokerConnection +from carrot.messaging import Consumer + + +def run(): + conn = DjangoBrokerConnection() + + consumer = Consumer(connection=conn, queue="oxdb-bg", + exchange="oxdb-bg", + routing_key="oxdb-bg") + def handle_background_tasks_callback(message_data, message): + print("Got feed import message") + print message_data + if 'loadIMDb' in message_data: + imdbId = message_data['loadIMDb'] + load.loadIMDb(imdbId) + message.ack() + consumer.register_callback(handle_background_tasks_callback) + consumer.wait() # Go into the consumer loop. + diff --git a/oxdb/backend/management/__init__.py b/oxdb/backend/management/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/oxdb/backend/management/commands/__init__.py b/oxdb/backend/management/commands/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/oxdb/backend/management/commands/backgroundtasks.py b/oxdb/backend/management/commands/backgroundtasks.py new file mode 100644 index 000000000..fb9731d83 --- /dev/null +++ b/oxdb/backend/management/commands/backgroundtasks.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +# vi:si:et:sw=4:sts=4:ts=4 +# j@v2v.cc +import os +from os.path import join, dirname, basename, splitext, exists +from glob import glob + +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 dasks. + """ + help = 'listen to rabbitmq and execute background dasks.' + args = '' + + def handle(self, **options): + daemon.run() +