cablegates/oxdb/backend/daemon.py

34 lines
1.1 KiB
Python
Raw Normal View History

2009-12-31 15:06:26 +00:00
from carrot.connection import DjangoBrokerConnection
2010-01-16 20:42:11 +00:00
from carrot.messaging import Consumer, Publisher
from django.conf import settings
2009-12-31 15:06:26 +00:00
2010-01-16 20:42:11 +00:00
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()
2009-12-31 15:06:26 +00:00
def run():
conn = DjangoBrokerConnection()
consumer = Consumer(connection=conn, queue="oxdb-bg",
exchange="oxdb-bg",
routing_key="oxdb-bg")
2010-01-16 20:42:11 +00:00
def handle_background_tasks_callback(data, message):
2010-01-22 23:25:48 +00:00
print("Got bg message")
2010-01-16 20:42:11 +00:00
print data
if 'loadIMDb' in data:
2010-01-22 23:25:48 +00:00
imdbId = data['loadIMDb']
2009-12-31 15:06:26 +00:00
load.loadIMDb(imdbId)
2010-01-16 20:42:11 +00:00
elif 'findMovie' in data:
f = models.File.objects.get(pk=data['findMovie'])
f.findMovie()
2009-12-31 15:06:26 +00:00
message.ack()
consumer.register_callback(handle_background_tasks_callback)
consumer.wait() # Go into the consumer loop.