Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #54 from Koed00/dev
Adds IronMQ broker
- Loading branch information
Showing
15 changed files
with
209 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
from django_q.conf import Conf | ||
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): | ||
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.BULK)['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 | ||
|
||
def info(self): | ||
return 'IronMQ' | ||
|
||
def queue_size(self): | ||
return self.connection.size() | ||
|
||
def delete_queue(self): | ||
return self.connection.delete_queue()['msg'] | ||
|
||
def purge_queue(self): | ||
return self.connection.clear() | ||
|
||
def delete(self, task_id): | ||
return self.connection.delete(task_id)['msg'] | ||
|
||
def fail(self, task_id): | ||
self.delete(task_id) | ||
|
||
def acknowledge(self, task_id): | ||
return self.delete(task_id) | ||
|
||
@staticmethod | ||
def get_connection(list_key=Conf.PREFIX): | ||
ironmq = IronMQ(name=None, **Conf.IRON_MQ) | ||
return ironmq.queue(queue_name=list_key) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ hiredis | |
redis | ||
psutil | ||
django-redis | ||
iron-mq |
Oops, something went wrong.