mirror of
https://github.com/zulip/zulip.git
synced 2025-11-10 17:07:07 +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):
|
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)
|
||||||
|
|||||||
Reference in New Issue
Block a user