mirror of https://github.com/zulip/zulip.git
run-dev: Extract server_processes().
We clean up the code related to launching processes here. We extract: server_processes We also extract these helper for webpack stuff: do_one_time_webpack_compile start_webpack_watcher And then we move the code to actually launch them lexically within the file (so as not to be obscured by various function definitions).
This commit is contained in:
parent
9cdc9cbca6
commit
28a2b90b04
|
@ -136,9 +136,9 @@ if not os.path.exists(os.path.dirname(pid_file_path)):
|
||||||
with open(pid_file_path, 'w+') as f:
|
with open(pid_file_path, 'w+') as f:
|
||||||
f.write(str(os.getpgrp()) + "\n")
|
f.write(str(os.getpgrp()) + "\n")
|
||||||
|
|
||||||
# Pass --nostatic because we configure static serving ourselves in
|
def server_processes() -> List[List[str]]:
|
||||||
# zulip/urls.py.
|
main_cmds = [
|
||||||
cmds = [['./manage.py', 'runserver'] +
|
['./manage.py', 'runserver'] +
|
||||||
manage_args + runserver_args + ['127.0.0.1:%d' % (django_port,)],
|
manage_args + runserver_args + ['127.0.0.1:%d' % (django_port,)],
|
||||||
['env', 'PYTHONUNBUFFERED=1', './manage.py', 'runtornado'] +
|
['env', 'PYTHONUNBUFFERED=1', './manage.py', 'runtornado'] +
|
||||||
manage_args + ['127.0.0.1:%d' % (tornado_port,)],
|
manage_args + ['127.0.0.1:%d' % (tornado_port,)],
|
||||||
|
@ -147,14 +147,19 @@ cmds = [['./manage.py', 'runserver'] +
|
||||||
'./puppet/zulip/files/postgresql/process_fts_updates'],
|
'./puppet/zulip/files/postgresql/process_fts_updates'],
|
||||||
['./manage.py', 'deliver_scheduled_messages'],
|
['./manage.py', 'deliver_scheduled_messages'],
|
||||||
['/srv/zulip-thumbor-venv/bin/thumbor', '-c', './zthumbor/thumbor.conf',
|
['/srv/zulip-thumbor-venv/bin/thumbor', '-c', './zthumbor/thumbor.conf',
|
||||||
'-p', '%s' % (thumbor_port,)]]
|
'-p', '%s' % (thumbor_port,)],
|
||||||
if options.test:
|
]
|
||||||
|
|
||||||
|
return main_cmds
|
||||||
|
|
||||||
|
def do_one_time_webpack_compile() -> None:
|
||||||
# We just need to compile webpack assets once at startup, not run a daemon,
|
# We just need to compile webpack assets once at startup, not run a daemon,
|
||||||
# in test mode. Additionally, webpack-dev-server doesn't support running 2
|
# in test mode. Additionally, webpack-dev-server doesn't support running 2
|
||||||
# copies on the same system, so this model lets us run the casper tests
|
# copies on the same system, so this model lets us run the casper tests
|
||||||
# with a running development server.
|
# with a running development server.
|
||||||
subprocess.check_call(['./tools/webpack', '--quiet', '--test'])
|
subprocess.check_call(['./tools/webpack', '--quiet', '--test'])
|
||||||
else:
|
|
||||||
|
def start_webpack_watcher() -> None:
|
||||||
webpack_cmd = ['./tools/webpack', '--watch', '--port', str(webpack_port)]
|
webpack_cmd = ['./tools/webpack', '--watch', '--port', str(webpack_port)]
|
||||||
if options.minify:
|
if options.minify:
|
||||||
webpack_cmd.append('--minify')
|
webpack_cmd.append('--minify')
|
||||||
|
@ -166,10 +171,7 @@ else:
|
||||||
webpack_cmd += ["--host", options.interface]
|
webpack_cmd += ["--host", options.interface]
|
||||||
else:
|
else:
|
||||||
webpack_cmd += ["--host", "0.0.0.0"]
|
webpack_cmd += ["--host", "0.0.0.0"]
|
||||||
cmds.append(webpack_cmd)
|
subprocess.Popen(webpack_cmd)
|
||||||
for cmd in cmds:
|
|
||||||
subprocess.Popen(cmd)
|
|
||||||
|
|
||||||
|
|
||||||
def transform_url(protocol: str, path: str, query: str, target_port: int, target_host: str) -> str:
|
def transform_url(protocol: str, path: str, query: str, target_port: int, target_host: str) -> str:
|
||||||
# generate url with target host
|
# generate url with target host
|
||||||
|
@ -181,7 +183,6 @@ def transform_url(protocol: str, path: str, query: str, target_port: int, target
|
||||||
newpath = urlunparse((protocol, host, path, '', query, ''))
|
newpath = urlunparse((protocol, host, path, '', query, ''))
|
||||||
return newpath
|
return newpath
|
||||||
|
|
||||||
|
|
||||||
@gen.engine
|
@gen.engine
|
||||||
def fetch_request(url: str, callback: Any, **kwargs: Any) -> "Generator[Callable[..., Any], Any, None]":
|
def fetch_request(url: str, callback: Any, **kwargs: Any) -> "Generator[Callable[..., Any], Any, None]":
|
||||||
# use large timeouts to handle polling requests
|
# use large timeouts to handle polling requests
|
||||||
|
@ -345,6 +346,14 @@ def print_listeners() -> None:
|
||||||
proxy_warning = f"Only the proxy port ({proxy_port}) is exposed."
|
proxy_warning = f"Only the proxy port ({proxy_port}) is exposed."
|
||||||
print(WARNING + "Note to Vagrant users: " + ENDC + proxy_warning + '\n')
|
print(WARNING + "Note to Vagrant users: " + ENDC + proxy_warning + '\n')
|
||||||
|
|
||||||
|
if options.test:
|
||||||
|
do_one_time_webpack_compile()
|
||||||
|
else:
|
||||||
|
start_webpack_watcher()
|
||||||
|
|
||||||
|
for cmd in server_processes():
|
||||||
|
subprocess.Popen(cmd)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
app = Application(enable_logging=options.enable_tornado_logging)
|
app = Application(enable_logging=options.enable_tornado_logging)
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Reference in New Issue