2017-11-16 00:53:11 +01:00
|
|
|
import tornado.web
|
2016-11-27 04:56:26 +01:00
|
|
|
from django.conf import settings
|
2022-09-30 03:08:23 +02:00
|
|
|
from django.core.handlers.base import BaseHandler
|
2022-03-17 22:09:11 +01:00
|
|
|
from tornado import autoreload
|
2016-11-27 04:56:26 +01:00
|
|
|
|
2022-04-16 02:30:58 +02:00
|
|
|
from zerver.lib.queue import TornadoQueueClient
|
2016-11-27 04:56:26 +01:00
|
|
|
from zerver.tornado.handlers import AsyncDjangoHandler
|
|
|
|
|
2020-06-11 00:54:34 +02:00
|
|
|
|
2022-04-16 02:30:58 +02:00
|
|
|
def setup_tornado_rabbitmq(queue_client: TornadoQueueClient) -> None: # nocoverage
|
2020-10-23 02:43:28 +02:00
|
|
|
# When tornado is shut down, disconnect cleanly from RabbitMQ
|
2024-03-01 02:56:37 +01:00
|
|
|
autoreload.add_reload_hook(queue_client.close)
|
2017-07-21 06:55:25 +02:00
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2023-12-09 22:31:30 +01:00
|
|
|
def create_tornado_application(*, autoreload: bool = False) -> tornado.web.Application:
|
2022-09-30 03:08:23 +02:00
|
|
|
django_handler = BaseHandler()
|
|
|
|
django_handler.load_middleware()
|
|
|
|
|
2018-07-13 12:58:16 +02:00
|
|
|
urls = (
|
|
|
|
r"/json/events",
|
|
|
|
r"/api/v1/events",
|
|
|
|
r"/api/v1/events/internal",
|
2024-02-08 20:10:25 +01:00
|
|
|
r"/api/internal/notify_tornado",
|
2024-02-08 20:57:16 +01:00
|
|
|
r"/api/internal/web_reload_clients",
|
2018-07-13 12:58:16 +02:00
|
|
|
)
|
2016-11-27 04:56:26 +01:00
|
|
|
|
2020-09-16 22:19:07 +02:00
|
|
|
return tornado.web.Application(
|
2022-09-30 03:08:23 +02:00
|
|
|
[(url, AsyncDjangoHandler, dict(django_handler=django_handler)) for url in urls],
|
2020-09-16 22:19:07 +02:00
|
|
|
debug=settings.DEBUG,
|
2023-12-09 22:31:30 +01:00
|
|
|
autoreload=autoreload,
|
2020-09-16 22:19:07 +02:00
|
|
|
# Disable Tornado's own request logging, since we have our own
|
2021-02-12 08:19:30 +01:00
|
|
|
log_function=lambda x: None,
|
2020-09-16 22:19:07 +02:00
|
|
|
)
|