Fix deprectae warnings with amqp >= 2.x

remotes/origin/issue/4795/notification_even_they_are_disabled
David Barragán Merino 2016-11-24 11:53:40 +01:00
parent ad8b2549d7
commit 39dabdb0c8
1 changed files with 16 additions and 12 deletions

View File

@ -50,17 +50,21 @@ class EventsPushBackend(base.BaseEventsPushBackend):
def emit_event(self, message:str, *, routing_key:str, channel:str="events"):
connection = _make_rabbitmq_connection(self.url)
try:
rchannel = connection.channel()
connection.connect()
except ConnectionRefusedError:
log.error("EventsPushBackend: Unable to connect with RabbitMQ at {}".format(self.url),
exc_info=True)
else:
try:
message = AmqpMessage(message)
rchannel = connection.channel()
rchannel.exchange_declare(exchange=channel, type="topic", auto_delete=True)
rchannel.basic_publish(message, routing_key=routing_key, exchange=channel)
rchannel.close()
except Exception:
log.error("Unhandled exception", exc_info=True)
log.error("EventsPushBackend: Unhandled exception",
exc_info=True)
finally:
connection.close()