mirror of https://github.com/celery/kombu.git
maybe_declare should not cache declaration if entity is not durable
This commit is contained in:
parent
4c599f9719
commit
2578e442f0
|
@ -46,6 +46,9 @@ class MaybeChannelBound(Object):
|
||||||
_channel = None
|
_channel = None
|
||||||
_is_bound = False
|
_is_bound = False
|
||||||
|
|
||||||
|
#: Defines whether maybe_declare can skip declaring this entity twice.
|
||||||
|
can_cache_declaration = False
|
||||||
|
|
||||||
def __call__(self, channel):
|
def __call__(self, channel):
|
||||||
"""`self(channel) -> self.bind(channel)`"""
|
"""`self(channel) -> self.bind(channel)`"""
|
||||||
return self.bind(channel)
|
return self.bind(channel)
|
||||||
|
|
|
@ -20,7 +20,7 @@ def maybe_declare(entity, channel):
|
||||||
declared = declared_entities[channel.connection.client]
|
declared = declared_entities[channel.connection.client]
|
||||||
if not entity.is_bound:
|
if not entity.is_bound:
|
||||||
entity = entity(channel)
|
entity = entity(channel)
|
||||||
if entity not in declared:
|
if not entity.can_cache_declaration or entity not in declared:
|
||||||
entity.declare()
|
entity.declare()
|
||||||
declared.add(entity)
|
declared.add(entity)
|
||||||
return True
|
return True
|
||||||
|
|
|
@ -236,6 +236,9 @@ class Exchange(MaybeChannelBound):
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return super(Exchange, self).__repr__("Exchange %s(%s)" % (self.name,
|
return super(Exchange, self).__repr__("Exchange %s(%s)" % (self.name,
|
||||||
self.type))
|
self.type))
|
||||||
|
@property
|
||||||
|
def can_cache_declaration(self):
|
||||||
|
return self.durable
|
||||||
|
|
||||||
|
|
||||||
class Queue(MaybeChannelBound):
|
class Queue(MaybeChannelBound):
|
||||||
|
@ -512,3 +515,7 @@ class Queue(MaybeChannelBound):
|
||||||
"Queue %s -> %s -> %s" % (self.name,
|
"Queue %s -> %s -> %s" % (self.name,
|
||||||
self.exchange,
|
self.exchange,
|
||||||
self.routing_key))
|
self.routing_key))
|
||||||
|
|
||||||
|
@property
|
||||||
|
def can_cache_declaration(self):
|
||||||
|
return self.durable
|
||||||
|
|
Loading…
Reference in New Issue