cablegates/oxdb/backend/daemon.py
2010-01-25 20:27:10 +05:30

33 lines
1.1 KiB
Python

from carrot.connection import DjangoBrokerConnection
from carrot.messaging import Consumer, Publisher
from django.conf import settings
import load
import models
def send_bg_message(msg):
conn = DjangoBrokerConnection()
publisher = Publisher(connection=conn, exchange="oxdb-bg",
routing_key="oxdb-bg")
publisher.send(msg)
publisher.close()
def run():
conn = DjangoBrokerConnection()
consumer = Consumer(connection=conn, queue="oxdb-bg",
exchange="oxdb-bg",
routing_key="oxdb-bg")
def handle_background_tasks_callback(data, message):
print("Got bg message")
print data
if 'loadIMDb' in data:
imdbId = data['loadIMDb']
load.loadIMDb(imdbId)
elif 'findMovie' in data:
f = models.File.objects.get(pk=data['findMovie'])
f.findMovie()
message.ack()
consumer.register_callback(handle_background_tasks_callback)
consumer.wait() # Go into the consumer loop.