mirror of https://github.com/zulip/zulip.git
Look up client descriptors by handler_id.
Previously, client descriptors were referenced directly from the handler object. Once we split the Tornado process into separate queue and connection servers, these will no longer be in the same process, so we need to reference them by ID instead.
This commit is contained in:
parent
ea6211c041
commit
c7e3c3ce38
|
@ -148,8 +148,7 @@ class ClientDescriptor(object):
|
||||||
|
|
||||||
def connect_handler(self, handler_id):
|
def connect_handler(self, handler_id):
|
||||||
self.current_handler_id = handler_id
|
self.current_handler_id = handler_id
|
||||||
handler = get_handler_by_id(self.current_handler_id)
|
set_descriptor_by_handler_id(handler_id, self)
|
||||||
handler.client_descriptor = self
|
|
||||||
self.last_connection_time = time.time()
|
self.last_connection_time = time.time()
|
||||||
def timeout_callback():
|
def timeout_callback():
|
||||||
self._timeout_handle = None
|
self._timeout_handle = None
|
||||||
|
@ -164,7 +163,7 @@ class ClientDescriptor(object):
|
||||||
if self.current_handler_id:
|
if self.current_handler_id:
|
||||||
handler = get_handler_by_id(self.current_handler_id)
|
handler = get_handler_by_id(self.current_handler_id)
|
||||||
request = handler._request
|
request = handler._request
|
||||||
handler.client_descriptor = None
|
delete_descriptor_by_handler_id(self.current_handler_id, None)
|
||||||
if client_closed:
|
if client_closed:
|
||||||
logging.info("Client disconnected for queue %s (%s via %s)" %
|
logging.info("Client disconnected for queue %s (%s via %s)" %
|
||||||
(self.event_queue.id, self.user_profile_email,
|
(self.event_queue.id, self.user_profile_email,
|
||||||
|
@ -179,6 +178,17 @@ class ClientDescriptor(object):
|
||||||
do_gc_event_queues([self.event_queue.id], [self.user_profile_id],
|
do_gc_event_queues([self.event_queue.id], [self.user_profile_id],
|
||||||
[self.realm_id])
|
[self.realm_id])
|
||||||
|
|
||||||
|
descriptors_by_handler_id = {}
|
||||||
|
|
||||||
|
def get_descriptor_by_handler_id(handler_id):
|
||||||
|
return descriptors_by_handler_id.get(handler_id)
|
||||||
|
|
||||||
|
def set_descriptor_by_handler_id(handler_id, client_descriptor):
|
||||||
|
descriptors_by_handler_id[handler_id] = client_descriptor
|
||||||
|
|
||||||
|
def delete_descriptor_by_handler_id(handler_id, client_descriptor):
|
||||||
|
del descriptors_by_handler_id[handler_id]
|
||||||
|
|
||||||
def compute_full_event_type(event):
|
def compute_full_event_type(event):
|
||||||
if event["type"] == "update_message_flags":
|
if event["type"] == "update_message_flags":
|
||||||
if event["all"]:
|
if event["all"]:
|
||||||
|
|
|
@ -21,7 +21,8 @@ from tornado import ioloop
|
||||||
from zerver.lib.debug import interactive_debug_listen
|
from zerver.lib.debug import interactive_debug_listen
|
||||||
from zerver.lib.response import json_response
|
from zerver.lib.response import json_response
|
||||||
from zerver.lib.event_queue import process_notification, missedmessage_hook
|
from zerver.lib.event_queue import process_notification, missedmessage_hook
|
||||||
from zerver.lib.event_queue import setup_event_queue, add_client_gc_hook
|
from zerver.lib.event_queue import setup_event_queue, add_client_gc_hook, \
|
||||||
|
get_descriptor_by_handler_id
|
||||||
from zerver.lib.handlers import allocate_handler_id
|
from zerver.lib.handlers import allocate_handler_id
|
||||||
from zerver.lib.queue import setup_tornado_rabbitmq
|
from zerver.lib.queue import setup_tornado_rabbitmq
|
||||||
from zerver.lib.socket import get_sockjs_router, respond_send_message
|
from zerver.lib.socket import get_sockjs_router, respond_send_message
|
||||||
|
@ -187,8 +188,9 @@ class AsyncDjangoHandler(tornado.web.RequestHandler, base.BaseHandler):
|
||||||
self.get()
|
self.get()
|
||||||
|
|
||||||
def on_connection_close(self):
|
def on_connection_close(self):
|
||||||
if self.client_descriptor is not None:
|
client_descriptor = get_descriptor_by_handler_id(self.handler_id)
|
||||||
self.client_descriptor.disconnect_handler(client_closed=True)
|
if client_descriptor is not None:
|
||||||
|
client_descriptor.disconnect_handler(client_closed=True)
|
||||||
|
|
||||||
# Based on django.core.handlers.base: get_response
|
# Based on django.core.handlers.base: get_response
|
||||||
def get_response(self, request):
|
def get_response(self, request):
|
||||||
|
|
Loading…
Reference in New Issue