queue: Refactor SimpleQueueClient initialization

In anticipation of subclassing.

(imported from commit 1ebee932aed1b472bf9a8ab6d9bc30519f587c83)
This commit is contained in:
Keegan McAllister
2013-01-18 13:15:09 -05:00
parent d349de903b
commit 89c544f21f

View File

@@ -9,12 +9,17 @@ import simplejson
class SimpleQueueClient(object): class SimpleQueueClient(object):
def __init__(self): def __init__(self):
self.queues = set() self.queues = set()
self.channel = None
self._connect()
credentials = pika.PlainCredentials('humbug', settings.RABBITMQ_PASSWORD) def _connect(self):
parameters = pika.ConnectionParameters('localhost', self.connection = pika.BlockingConnection(self._get_parameters())
credentials=credentials) self.channel = self.connection.channel()
self.connection = pika.BlockingConnection(parameters)
self.channel = self.connection.channel() def _get_parameters(self):
return pika.ConnectionParameters('localhost',
credentials = pika.PlainCredentials(
'humbug', settings.RABBITMQ_PASSWORD))
@classmethod @classmethod
def get_instance(cls): def get_instance(cls):
@@ -23,6 +28,9 @@ class SimpleQueueClient(object):
cls._instance = cls() cls._instance = cls()
return cls._instance return cls._instance
def ready(self):
return self.channel is not None
def create_queue(self, queue_name): def create_queue(self, queue_name):
# Initialize the queues we need # Initialize the queues we need
self.channel.queue_declare(queue=queue_name, durable=True) self.channel.queue_declare(queue=queue_name, durable=True)