mirror of https://github.com/zulip/zulip.git
Send responses from fetch_events in dict format.
This commit is contained in:
parent
485e46f136
commit
bf43db0dad
|
@ -469,13 +469,14 @@ def fetch_events(query):
|
|||
was_connected = client.finish_current_handler()
|
||||
|
||||
if not client.event_queue.empty() or dont_block:
|
||||
ret = {'events': client.event_queue.contents()}
|
||||
response = dict(events=client.event_queue.contents(),
|
||||
handler_id=handler_id)
|
||||
if orig_queue_id is None:
|
||||
ret['queue_id'] = queue_id
|
||||
extra_log_data = "[%s/%s]" % (queue_id, len(ret["events"]))
|
||||
response['queue_id'] = queue_id
|
||||
extra_log_data = "[%s/%s]" % (queue_id, len(response["events"]))
|
||||
if was_connected:
|
||||
extra_log_data += " [was connected]"
|
||||
return (ret, extra_log_data)
|
||||
return dict(type="response", response=response, extra_log_data=extra_log_data)
|
||||
|
||||
# After this point, dont_block=False, the queue is empty, and we
|
||||
# have a pre-existing queue, so we wait for new events.
|
||||
|
@ -483,10 +484,13 @@ def fetch_events(query):
|
|||
logging.info("Disconnected handler for queue %s (%s/%s)" % (queue_id, user_profile_email,
|
||||
client_type_name))
|
||||
except JsonableError as e:
|
||||
if hasattr(e, 'to_json_error_msg') and callable(e.to_json_error_msg):
|
||||
return dict(type="error", handler_id=handler_id,
|
||||
message=e.to_json_error_msg())
|
||||
raise e
|
||||
|
||||
client.connect_handler(handler_id, client_type_name)
|
||||
return (RespondAsynchronously, None)
|
||||
return dict(type="async")
|
||||
|
||||
# The following functions are called from Django
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ from django.test import TestCase
|
|||
|
||||
from zerver.lib.initial_password import initial_password
|
||||
from zerver.lib.db import TimeTrackingCursor
|
||||
from zerver.lib.handlers import allocate_handler_id
|
||||
from zerver.lib import cache
|
||||
from zerver.lib import event_queue
|
||||
from zerver.worker import queue_processors
|
||||
|
|
|
@ -82,9 +82,13 @@ def get_events_backend(request, user_profile, handler,
|
|||
last_connection_time = time.time(),
|
||||
narrow = narrow)
|
||||
|
||||
(result, log_data) = fetch_events(events_query)
|
||||
request._log_data['extra'] = log_data
|
||||
if result == RespondAsynchronously:
|
||||
result = fetch_events(events_query)
|
||||
if "extra_log_data" in result:
|
||||
request._log_data['extra'] = result["extra_log_data"]
|
||||
|
||||
if result["type"] == "async":
|
||||
handler._request = request
|
||||
return result
|
||||
return json_success(result)
|
||||
return RespondAsynchronously
|
||||
if result["type"] == "error":
|
||||
return json_error(result["message"])
|
||||
return json_success(result["response"])
|
||||
|
|
Loading…
Reference in New Issue