Esempio n. 1
0
async def serve() -> None:
    host = os.environ.get("GRPC_HOST", "0.0.0.0")
    port = int(os.environ.get("GRPC_PORT", "50051"))
    debug = os.environ.get("DEBUG", "FALSE").upper() == "TRUE"

    if not debug:
        matplotlib.use("agg")

    log = configure_logger()

    log.info("creating resources")
    resources = Resources()
    service = server.Server([StalkReporter(resources, debug)])

    log.info("starting up service")
    with utils.graceful_exit([service]):
        await service.start(host, port)
        log.info(f"serving grpc on {host}:{port}")
        await service.wait_closed()
        log.info("shutting down service")

    log.info("service shutdown complete")
    log.info("releasing resource")
    await resources.shutdown()
    log.info("shutdown complete")
Esempio n. 2
0
 def __init__(
         self,
         golem_app,
         port: int,
         lifecycle: AppLifecycleHandler,
         ssl_context: Optional[ssl.SSLContext] = None,
 ) -> None:
     self._server = server.Server(
         handlers=[golem_app, Health()],
         loop=asyncio.get_event_loop(),
     )
     self._port = port
     self._lifecycle = lifecycle
     self._ssl_context = ssl_context
Esempio n. 3
0
    async def __aenter__(self):
        host = '127.0.0.1'
        with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
            s.bind(('127.0.0.1', 0))
            _, port = s.getsockname()

        handler = self.handler_cls()
        self.server = server.Server([handler], loop=self.loop, codec=self.codec)
        await self.server.start(host, port)

        self.channel = client.Channel(host, port, loop=self.loop,
                                      codec=self.codec)
        stub = self.stub_cls(self.channel)
        return handler, stub