2020-06-11 00:54:34 +02:00
|
|
|
import json
|
|
|
|
import os
|
2020-06-27 03:03:26 +02:00
|
|
|
from urllib.parse import urlsplit
|
2020-06-11 00:54:34 +02:00
|
|
|
|
2018-11-02 23:51:05 +01:00
|
|
|
from django.conf import settings
|
|
|
|
|
|
|
|
from zerver.models import Realm
|
2020-06-11 00:54:34 +02:00
|
|
|
|
2018-11-07 02:13:37 +01:00
|
|
|
shard_map = {}
|
|
|
|
if os.path.exists("/etc/zulip/sharding.json"):
|
|
|
|
with open("/etc/zulip/sharding.json") as f:
|
|
|
|
shard_map = json.loads(f.read())
|
2018-11-02 23:51:05 +01:00
|
|
|
|
|
|
|
def get_tornado_port(realm: Realm) -> int:
|
2018-11-03 01:07:21 +01:00
|
|
|
if settings.TORNADO_SERVER is None:
|
|
|
|
return 9993
|
2018-11-02 23:51:05 +01:00
|
|
|
if settings.TORNADO_PROCESSES == 1:
|
2020-06-27 03:03:26 +02:00
|
|
|
r = urlsplit(settings.TORNADO_SERVER)
|
|
|
|
assert r.port is not None
|
|
|
|
return r.port
|
2018-11-07 02:13:37 +01:00
|
|
|
return shard_map.get(realm.host, 9800)
|
2018-11-02 23:51:05 +01:00
|
|
|
|
|
|
|
def get_tornado_uri(realm: Realm) -> str:
|
|
|
|
if settings.TORNADO_PROCESSES == 1:
|
|
|
|
return settings.TORNADO_SERVER
|
|
|
|
|
|
|
|
port = get_tornado_port(realm)
|
2020-06-13 08:59:37 +02:00
|
|
|
return f"http://127.0.0.1:{port}"
|
2018-11-03 00:06:13 +01:00
|
|
|
|
|
|
|
def notify_tornado_queue_name(port: int) -> str:
|
|
|
|
if settings.TORNADO_PROCESSES == 1:
|
|
|
|
return "notify_tornado"
|
2020-06-13 08:59:37 +02:00
|
|
|
return f"notify_tornado_port_{port}"
|