Files
zulip/zerver/tornado/sharding.py
Anders Kaseorg 365fe0b3d5 python: Sort imports with isort.
Fixes #2665.

Regenerated by tabbott with `lint --fix` after a rebase and change in
parameters.

Note from tabbott: In a few cases, this converts technical debt in the
form of unsorted imports into different technical debt in the form of
our largest files having very long, ugly import sequences at the
start.  I expect this change will increase pressure for us to split
those files, which isn't a bad thing.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-06-11 16:45:32 -07:00

31 lines
856 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:
if settings.TORNADO_SERVER is None:
return 9993
if settings.TORNADO_PROCESSES == 1:
return int(settings.TORNADO_SERVER.split(":")[-1])
return shard_map.get(realm.host, 9800)
def get_tornado_uri(realm: Realm) -> str:
if settings.TORNADO_PROCESSES == 1:
return settings.TORNADO_SERVER
port = get_tornado_port(realm)
return "http://127.0.0.1:%d" % (port,)
def notify_tornado_queue_name(port: int) -> str:
if settings.TORNADO_PROCESSES == 1:
return "notify_tornado"
return "notify_tornado_port_%d" % (port,)