Adds bulk get to ironmq

This commit is contained in:
Ilan Steemers
2015-09-08 13:37:33 +02:00
parent b56cc9da8f
commit 0ffae4519b
4 changed files with 17 additions and 7 deletions
+1
View File
@@ -7,6 +7,7 @@ class Broker(object):
self.connection = self.get_connection(list_key)
self.list_key = list_key
self.cache = self.get_cache()
self.task_cache = []
def enqueue(self, task):
"""
+14 -7
View File
@@ -1,18 +1,25 @@
from django_q.conf import Conf
from django_q.conf import Conf, logger
from django_q.brokers import Broker
from iron_mq import IronMQ
class IronMQBroker(Broker):
def enqueue(self, task):
return self.connection.post(task)['ids'][0]
def dequeue(self):
timeout = Conf.RETRY or None
task = self.connection.get(timeout=timeout, wait=1)['messages']
if task:
return task[0]['id'], task[0]['body']
t = None
if len(self.task_cache) > 0:
t = self.task_cache.pop()
else:
timeout = Conf.RETRY or None
tasks = self.connection.get(timeout=timeout, wait=1, max=Conf.IRON_MQ_MAX)['messages']
if tasks:
t = tasks.pop()
if tasks:
self.task_cache = tasks
if t:
return t['id'], t['body']
def ping(self):
return self.connection.name == self.list_key
@@ -41,4 +48,4 @@ class IronMQBroker(Broker):
@staticmethod
def get_connection(list_key=Conf.PREFIX):
ironmq = IronMQ(name=None, **Conf.IRON_MQ)
return ironmq.queue(queue_name=list_key)
return ironmq.queue(queue_name=list_key)
+1
View File
@@ -39,6 +39,7 @@ class Conf(object):
# IronMQ broker
IRON_MQ = conf.get('iron_mq', None)
IRON_MQ_MAX = conf.get('iron_mq_max', 1)
# Name of the cluster or site. For when you run multiple sites on one redis server
PREFIX = conf.get('name', 'default')
+1
View File
@@ -129,3 +129,4 @@ def test_ironmq():
assert broker.queue_size() == 0
# back to django-redis
Conf.IRON_MQ = None
Conf.DJANGO_REDIS = 'default'