Add logging for when we disconnected an active handler.

(imported from commit 18c21a93bdf14485e5656bd7a38f2069eb8f2aad)
This commit is contained in:
Tim Abbott
2013-12-11 17:07:43 -05:00
parent fcf6ec16aa
commit 291506a2b2
2 changed files with 9 additions and 1 deletions

View File

@@ -129,11 +129,13 @@ class ClientDescriptor(object):
self._timeout_handle = ioloop.add_timeout(heartbeat_time, timeout_callback)
def disconnect_handler(self):
was_connected = (self.current_handler is not None)
self.current_handler = None
if self._timeout_handle is not None:
ioloop = tornado.ioloop.IOLoop.instance()
ioloop.remove_timeout(self._timeout_handle)
self._timeout_handle = None
return was_connected
def cleanup(self):
do_gc_event_queues([self.event_queue.id], [self.user_profile_id],

View File

@@ -52,6 +52,7 @@ def get_events_backend(request, user_profile, handler = None,
if user_client is None:
user_client = request.client
was_connected = False
orig_queue_id = queue_id
if queue_id is None:
if dont_block:
@@ -70,16 +71,21 @@ def get_events_backend(request, user_profile, handler = None,
if user_profile.id != client.user_profile_id:
return json_error("You are not authorized to get events from this queue")
client.event_queue.prune(last_event_id)
client.disconnect_handler()
was_connected = client.disconnect_handler()
if not client.event_queue.empty() or dont_block:
ret = {'events': client.event_queue.contents()}
if orig_queue_id is None:
ret['queue_id'] = queue_id
request._log_data['extra'] = "[%s/%s]" % (queue_id, len(ret["events"]))
if was_connected:
request._log_data['extra'] += " [was connected]"
return json_success(ret)
handler._request = request
if was_connected:
logging.info("Disconnected handler for queue %s (%s/%s)" % (queue_id, user_profile.email,
user_client.name))
client.connect_handler(handler)
# runtornado recognizes this special return value.