Browse Source

Made AMQP backend connection lazy

Ask Solem 15 years ago
parent
commit
d72f8a57d4
1 changed files with 8 additions and 1 deletions
  1. 8 1
      celery/backends/amqp.py

+ 8 - 1
celery/backends/amqp.py

@@ -6,6 +6,7 @@ from celery.messaging import establish_connection
 from celery.backends.base import BaseBackend
 from celery.backends.base import BaseBackend
 
 
 
 
+
 class AMQPBackend(BaseBackend):
 class AMQPBackend(BaseBackend):
     """AMQP backend. Publish results by sending messages to the broker
     """AMQP backend. Publish results by sending messages to the broker
     using the task id as routing key.
     using the task id as routing key.
@@ -18,12 +19,18 @@ class AMQPBackend(BaseBackend):
 
 
     exchange = conf.RESULT_EXCHANGE
     exchange = conf.RESULT_EXCHANGE
     capabilities = ["ResultStore"]
     capabilities = ["ResultStore"]
+    _connection = None
 
 
     def __init__(self, *args, **kwargs):
     def __init__(self, *args, **kwargs):
         super(AMQPBackend, self).__init__(*args, **kwargs)
         super(AMQPBackend, self).__init__(*args, **kwargs)
-        self.connection = establish_connection()
         self._cache = {}
         self._cache = {}
 
 
+    @property
+    def connection(self):
+        if not self._connection:
+            self._connection = establish_connection()
+        return self._connection
+
     def _declare_queue(self, task_id, connection):
     def _declare_queue(self, task_id, connection):
         routing_key = task_id.replace("-", "")
         routing_key = task_id.replace("-", "")
         backend = connection.create_backend()
         backend = connection.create_backend()