Commit eb3a357c authored by dmitry.mashoshin's avatar dmitry.mashoshin
Browse files

Merge branch 'kpn/4/param_for_web.TCPSite' into 'master'

feat: #4 add proxy param for web.TCPSite

See merge request !15
parents f7e26736 51ac989e
import asyncio
import signal
from typing import Any
from aiohttp import web
import prometheus_client
......@@ -24,7 +25,7 @@ async def metrics(request):
class AioAppWrapper:
def __init__(self, _app, _port, _loop, **kwargs):
def __init__(self, _app, _port: int, _loop, **kwargs: Any): = _app
self.port = _port
self.loop = _loop
......@@ -33,10 +34,12 @@ class AioAppWrapper:
async def initialize(self):'Initialize web app on port {self.port}')
tcp_params = {}
if isinstance(self.runner_kwargs.get('tcp_params'), dict):
tcp_params = self.runner_kwargs.get('tcp_params', {})
self.runner = web.AppRunner(, **self.runner_kwargs)
await self.runner.setup()
site = web.TCPSite(self.runner, '', self.port)
site = web.TCPSite(self.runner, '', self.port, **tcp_params)
await site.start()
while True:
await asyncio.sleep(3600)
......@@ -68,6 +71,11 @@ class CoroutineWrapper:
class ApplicationWrapper:
"""Application wrapper for exporting metrics on prometheus
_loop (:obj:, optional): Event loop
def __init__(self, _loop=None):
self.loop = _loop
self.apps = []
......@@ -78,7 +86,22 @@ class ApplicationWrapper:
self.add_web_app(init_mertics_app(), _port=9091)
def add_web_app(self, _app, _port, **kwargs):
def add_web_app(self, _app: web.Application, _port: int, **kwargs: Any) -> None:
"""Add Application for start list
_app (obj): Application
_port (int): Application PORT to listed
**kwargs: Arbitrary keyword arguments.
kwargs[tcp_params] - for setup TCPSite params
'backlog': 256,
'reuse_address': True,
'reuse_port': True
AioAppWrapper(_app, _port, self.loop, **kwargs)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment