Update src/nucleus/cli/server.py
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
__author__ = 'RemiZOffAlex'
|
||||
__email__ = 'remizoffalex@mail.ru'
|
||||
|
||||
import asyncio
|
||||
import signal
|
||||
|
||||
from logging import getLogger
|
||||
|
||||
from nucleus.core import config, loop, broker
|
||||
from nucleus.domains.network.server import ServerProtocol
|
||||
from nucleus.domains.config.common import handler_config
|
||||
from nucleus.domains.config.log import handler_config_log
|
||||
from nucleus.domains.config.broker import handler_config_broker
|
||||
from nucleus.handlers.terminator import (
|
||||
handler_interrupt,
|
||||
handler_terminate
|
||||
)
|
||||
from nucleus.domains.http.models.response import Response
|
||||
|
||||
|
||||
log = getLogger(__name__)
|
||||
|
||||
|
||||
def handle_response(request):
|
||||
response = Response('index')
|
||||
return response()
|
||||
|
||||
|
||||
def handler_connection(*args, **kwargs):
|
||||
print(args, kwargs)
|
||||
return ServerProtocol(broker)
|
||||
|
||||
|
||||
async def server_run():
|
||||
host = config['server.host']
|
||||
port = config['server.port']
|
||||
server = await loop.create_server(
|
||||
handler_connection,
|
||||
host,
|
||||
port
|
||||
)
|
||||
async with server:
|
||||
await server.serve_forever()
|
||||
|
||||
print(f"======= Serving on http://{host}:{port}/ ======")
|
||||
|
||||
|
||||
def handler_server(args):
|
||||
loop.add_signal_handler(
|
||||
signal.SIGINT,
|
||||
handler_interrupt
|
||||
)
|
||||
loop.add_signal_handler(
|
||||
signal.SIGTERM,
|
||||
handler_terminate
|
||||
)
|
||||
|
||||
handler_config(args.config_path)
|
||||
handler_config_log()
|
||||
handler_config_broker()
|
||||
|
||||
loop.create_task(
|
||||
server_run()
|
||||
)
|
||||
|
||||
try:
|
||||
loop.run_forever()
|
||||
finally:
|
||||
loop.run_until_complete(
|
||||
loop.shutdown_asyncgens()
|
||||
)
|
||||
loop.close()
|
||||
Reference in New Issue
Block a user