-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
45 lines (35 loc) · 1.05 KB
/
run.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import logging
import click
from pythonjsonlogger import jsonlogger
from pongy import settings
@click.command(context_settings=dict(help_option_names=["-h", "--help"]))
@click.option("-d", "--daemon", is_flag=True, help="Run server.")
@click.option(
"-h",
"--host",
help="Hostname",
type=click.STRING,
default=settings.SERVER_HOST,
)
@click.option(
"-p",
"--port",
help="Port",
type=click.INT,
default=settings.SERVER_PORT,
)
def main(daemon: bool, host: str, port: int) -> None:
stream_handler = logging.StreamHandler()
stream_handler.setFormatter(jsonlogger.JsonFormatter(timestamp=True))
logging.basicConfig(level=settings.LOGGING_LEVEL, handlers=[stream_handler])
if daemon:
from aiohttp import web
from pongy.server.app import get_application
web.run_app(get_application(), host=host, port=port)
else:
import asyncio
from pongy.client.app import Application
app = Application(host, port)
asyncio.run(app())
if __name__ == "__main__":
main()