mirror of
https://github.com/zulip/zulip.git
synced 2025-11-09 08:26:11 +00:00
Register a tornado atexit handler to disconnect from rabbitmq
(imported from commit b70650070f1df548794a9e3ff2948d134fd0c5de)
This commit is contained in:
@@ -5,6 +5,7 @@ import simplejson
|
||||
import random
|
||||
import time
|
||||
import threading
|
||||
import atexit
|
||||
from collections import defaultdict
|
||||
|
||||
# This simple queuing library doesn't expose much of the power of
|
||||
@@ -46,6 +47,10 @@ class SimpleQueueClient(object):
|
||||
queue=queue,
|
||||
consumer_tag=self._generate_ctag(queue)))
|
||||
|
||||
def close(self):
|
||||
if self.connection:
|
||||
self.connection.close()
|
||||
|
||||
def ready(self):
|
||||
return self.channel is not None
|
||||
|
||||
@@ -180,6 +185,10 @@ if settings.RUNNING_INSIDE_TORNADO and settings.USING_RABBITMQ:
|
||||
elif settings.USING_RABBITMQ:
|
||||
queue_client = SimpleQueueClient()
|
||||
|
||||
def setup_tornado_rabbitmq():
|
||||
# When tornado is shut down, disconnect cleanly from rabbitmq
|
||||
atexit.register(lambda: queue_client.close())
|
||||
|
||||
# We using a simple lock to prevent multiple RabbitMQ messages being
|
||||
# sent to the SimpleQueueClient at the same time; this is a workaround
|
||||
# for an issue with the pika BlockingConnection where using
|
||||
|
||||
Reference in New Issue
Block a user