Files
zulip/zerver/tornado/sharding.py
Alex Vandiver e5f62d083e tornado: Merge the TORNADO_SERVER and TORNADO_PORTS configs.
Having both of these is confusing; TORNADO_SERVER is used only when
there is one TORNADO_PORT.  Its primary use is actually to be _unset_,
and signal that in-process handling is to be done.

Rename to USING_TORNADO, to parallel the existing USING_RABBITMQ, and
switch the places that used it for its contents to using
TORNADO_PORTS.
2020-09-21 15:36:16 -07:00

24 lines
628 B
Python

import json
import os
from django.conf import settings
from zerver.models import Realm
shard_map = {}
if os.path.exists("/etc/zulip/sharding.json"):
with open("/etc/zulip/sharding.json") as f:
shard_map = json.loads(f.read())
def get_tornado_port(realm: Realm) -> int:
return shard_map.get(realm.host, settings.TORNADO_PORTS[0])
def get_tornado_uri(realm: Realm) -> str:
port = get_tornado_port(realm)
return f"http://127.0.0.1:{port}"
def notify_tornado_queue_name(port: int) -> str:
if settings.TORNADO_PROCESSES == 1:
return "notify_tornado"
return f"notify_tornado_port_{port}"