mirror of
https://github.com/zulip/zulip.git
synced 2025-11-02 21:13:36 +00:00
response: Replace response.asynchronous attribute with new class.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
committed by
Tim Abbott
parent
134977b590
commit
bb6bd900cd
@@ -14,7 +14,7 @@ from django.urls import set_script_prefix
|
||||
from django.utils.cache import patch_vary_headers
|
||||
from tornado.wsgi import WSGIContainer
|
||||
|
||||
from zerver.lib.response import json_response
|
||||
from zerver.lib.response import AsynchronousResponse, json_response
|
||||
from zerver.tornado.descriptors import get_descriptor_by_handler_id
|
||||
|
||||
current_handler_id = 0
|
||||
@@ -153,7 +153,7 @@ class AsyncDjangoHandler(tornado.web.RequestHandler, base.BaseHandler):
|
||||
response = await sync_to_async(lambda: self.get_response(request), thread_sensitive=True)()
|
||||
|
||||
try:
|
||||
if hasattr(response, "asynchronous"):
|
||||
if isinstance(response, AsynchronousResponse):
|
||||
# We import async_request_timer_restart during runtime
|
||||
# to avoid cyclic dependency with zerver.lib.request
|
||||
from zerver.middleware import async_request_timer_stop
|
||||
|
||||
@@ -9,7 +9,7 @@ from django.utils.translation import gettext as _
|
||||
from zerver.decorator import internal_notify_view, process_client
|
||||
from zerver.lib.exceptions import JsonableError
|
||||
from zerver.lib.request import REQ, RequestNotes, has_request_variables
|
||||
from zerver.lib.response import json_success
|
||||
from zerver.lib.response import AsynchronousResponse, json_success
|
||||
from zerver.lib.validator import (
|
||||
check_bool,
|
||||
check_int,
|
||||
@@ -170,13 +170,11 @@ def get_events_backend(
|
||||
log_data["extra"] = result["extra_log_data"]
|
||||
|
||||
if result["type"] == "async":
|
||||
# Mark this response with .asynchronous; this will result in
|
||||
# Return an AsynchronousResponse; this will result in
|
||||
# Tornado discarding the response and instead long-polling the
|
||||
# request. See zulip_finish for more design details.
|
||||
handler._request = request
|
||||
response = json_success(request)
|
||||
response.asynchronous = True
|
||||
return response
|
||||
return AsynchronousResponse()
|
||||
if result["type"] == "error":
|
||||
raise result["exception"]
|
||||
return json_success(request, data=result["response"])
|
||||
|
||||
Reference in New Issue
Block a user