tornado: Extract create_tornado_application helper.

This commit is contained in:
Tim Abbott 2016-11-26 19:56:26 -08:00
parent 9e9066f77a
commit b83361bcfc
2 changed files with 27 additions and 14 deletions

View File

@ -19,10 +19,9 @@ from typing import Callable
from zerver.lib.debug import interactive_debug_listen
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.handlers import allocate_handler_id
from zerver.lib.queue import setup_tornado_rabbitmq
from zerver.lib.socket import get_sockjs_router, respond_send_message
from zerver.tornado.handlers import AsyncDjangoHandler
from zerver.lib.socket import respond_send_message
from zerver.tornado.application import create_tornado_application
import logging
import sys
@ -58,7 +57,7 @@ class Command(BaseCommand):
interactive_debug_listen()
import django
from tornado import httpserver, web
from tornado import httpserver
try:
addr, port = addrport.split(':')
@ -98,17 +97,8 @@ class Command(BaseCommand):
queue_client.register_json_consumer('tornado_return', respond_send_message)
try:
urls = (r"/notify_tornado",
r"/json/events",
r"/api/v1/events",
)
# Application is an instance of Django's standard wsgi handler.
application = web.Application([(url, AsyncDjangoHandler) for url in urls]
+ get_sockjs_router().urls,
debug=django.conf.settings.DEBUG,
# Disable Tornado's own request logging, since we have our own
log_function=lambda x: None)
application = create_tornado_application()
# start tornado web server in single-threaded mode
http_server = httpserver.HTTPServer(application,

View File

@ -0,0 +1,23 @@
from __future__ import absolute_import
from __future__ import print_function
from django.conf import settings
from zerver.lib.socket import get_sockjs_router
from zerver.tornado.handlers import AsyncDjangoHandler
import tornado.web
def create_tornado_application():
# type: () -> tornado.web.Application
urls = (r"/notify_tornado",
r"/json/events",
r"/api/v1/events",
)
# Application is an instance of Django's standard wsgi handler.
return tornado.web.Application([(url, AsyncDjangoHandler) for url in urls]
+ get_sockjs_router().urls,
debug=settings.DEBUG,
# Disable Tornado's own request logging, since we have our own
log_function=lambda x: None)