mirror of
https://github.com/zulip/zulip.git
synced 2025-11-05 22:43:42 +00:00
queue: Refactor SimpleQueueClient initialization
In anticipation of subclassing. (imported from commit 1ebee932aed1b472bf9a8ab6d9bc30519f587c83)
This commit is contained in:
@@ -9,12 +9,17 @@ import simplejson
|
||||
class SimpleQueueClient(object):
|
||||
def __init__(self):
|
||||
self.queues = set()
|
||||
self.channel = None
|
||||
self._connect()
|
||||
|
||||
credentials = pika.PlainCredentials('humbug', settings.RABBITMQ_PASSWORD)
|
||||
parameters = pika.ConnectionParameters('localhost',
|
||||
credentials=credentials)
|
||||
self.connection = pika.BlockingConnection(parameters)
|
||||
self.channel = self.connection.channel()
|
||||
def _connect(self):
|
||||
self.connection = pika.BlockingConnection(self._get_parameters())
|
||||
self.channel = self.connection.channel()
|
||||
|
||||
def _get_parameters(self):
|
||||
return pika.ConnectionParameters('localhost',
|
||||
credentials = pika.PlainCredentials(
|
||||
'humbug', settings.RABBITMQ_PASSWORD))
|
||||
|
||||
@classmethod
|
||||
def get_instance(cls):
|
||||
@@ -23,6 +28,9 @@ class SimpleQueueClient(object):
|
||||
cls._instance = cls()
|
||||
return cls._instance
|
||||
|
||||
def ready(self):
|
||||
return self.channel is not None
|
||||
|
||||
def create_queue(self, queue_name):
|
||||
# Initialize the queues we need
|
||||
self.channel.queue_declare(queue=queue_name, durable=True)
|
||||
|
||||
Reference in New Issue
Block a user