Пример #1
0
    async def launch(self):
        print(f"[Cluster Manager] Starting a total of {config.BOT_CLUSTERS} clusters.")

        self.bot = ModMail(cluster_id=0, cluster_count=int(config.BOT_CLUSTERS))
        await self.bot.start(worker=False)

        self.bot.id = (await self.bot.real_user()).id
        self.bot.state.id = self.bot.id

        async with self.bot.pool.acquire() as conn:
            exists = await conn.fetchrow(
                "SELECT EXISTS (SELECT relname FROM pg_class WHERE relname = 'data')"
            )
            if exists[0] is False:
                with open("schema.sql", "r") as file:
                    await conn.execute(file.read())

        for i in range(int(config.BOT_CLUSTERS)):
            self.instances.append(Instance(i + 1, loop=self.loop, main=self))

        self.write_targets()

        scheduler = Scheduler(loop=self.loop, bot=self.bot)
        loop.create_task(scheduler.launch())

        server = web.Server(self.handler)
        runner = web.ServerRunner(server)
        await runner.setup()
        site = web.TCPSite(runner, config.BOT_API_HOST, int(config.BOT_API_PORT))
        await site.start()
Пример #2
0
async def main():
    server = web.Server(handler)
    runner = web.ServerRunner(server)
    await runner.setup()
    site = web.TCPSite(runner, addr, port)
    await site.start()
    logger.info("======= Serving on http://127.0.0.1:8080/ ======")
Пример #3
0
async def init():
    server = web.Server(hello)
    runner = web.ServerRunner(server)
    await runner.setup()
    site = web.TCPSite(runner, 'localhost', 8083)
    await site.start()
    await asyncio.sleep(100 * 3600)
Пример #4
0
async def startServ():
    server = web.Server(handle)
    runner = web.ServerRunner(server)
    await runner.setup()
    site = web.TCPSite(runner, 'localhost', 8080)
    await site.start()
    print("STARTING SERVER")
Пример #5
0
async def http_server():
    server = web.Server(handler)
    runner = web.ServerRunner(server)
    await runner.setup()
    site = web.TCPSite(runner, '127.0.0.1', 8090)
    await site.start()
    await asyncio.sleep(100 * 3600)
Пример #6
0
    async def _run(self) -> None:
        runner = web.ServerRunner(self.server)
        await runner.setup()
        site = web.TCPSite(runner, self.host, self.port)
        await site.start()

        await self.cancel_token.wait()
Пример #7
0
 async def _start_http_server(self) -> None:
     """Start http server."""
     server = web.Server(self._http_handler)
     runner = web.ServerRunner(server)
     await runner.setup()
     self.http_server = web.TCPSite(runner, self.host, self.port)
     await self.http_server.start()
Пример #8
0
async def main():
    server = web.Server(handler)
    runner = web.ServerRunner(server)
    await runner.setup()
    site = web.TCPSite(runner, 'localhost', port)
    site._shutdown_timeout = time_out
    await site.start()
Пример #9
0
 async def _run(self) -> None:
     runner = web.ServerRunner(self.server)
     await runner.setup()
     site = web.TCPSite(runner, self.host, self.port)
     await site.start()
     self.logger.info('HTTP started at: %s', site.name)
     await self.cancellation()
Пример #10
0
    async def _run(self) -> None:
        runner = web.ServerRunner(self.server)
        await runner.setup()
        site = web.TCPSite(runner, self.host, self.port)
        self.logger.info("Running HTTP Server %s:%d", self.host, self.port)
        await site.start()

        await self.cancellation()
Пример #11
0
async def main():
    server = web.Server(handler)
    runner = web.ServerRunner(server)
    await runner.setup()
    site = web.TCPSite(runner, "localhost", 8080)
    await site.start()
    print("======= Serving on http://127.0.0.1:8080/ ======")
    await asyncio.sleep(100 * 3600)
Пример #12
0
async def serve():
    server = web.Server(handler)
    runner = web.ServerRunner(server)
    await runner.setup()
    site = web.TCPSite(runner, port=PORT)
    await site.start()

    print('Listening  on port %d ...' % PORT)
Пример #13
0
 async def start(self):
     self._server = web.Server(self.handler)
     self._runner = web.ServerRunner(self._server)
     await self._runner.setup()
     self._site = web.TCPSite(self._runner, self._address, self._port,
                              ssl_context=self._ssl_context,
                              shutdown_timeout=self.SHUTDOWN_TIMEOUT)
     await self._site.start()
     self._logger.info("Server ready.")
Пример #14
0
async def main():
    global session
    session = aiohttp.ClientSession()
    server = web.Server(handler)
    runner = web.ServerRunner(server)
    await runner.setup()
    site = web.TCPSite(runner, "0.0.0.0", 8080)
    await site.start()
    print("Serving")
Пример #15
0
    async def listen(self) -> None:
        """Starts the HTTP listener."""
        logger.debug("Starting HTTP listener...")
        server = web.Server(self.handler)
        runner = web.ServerRunner(server)

        await runner.setup()
        site = web.TCPSite(runner, "localhost", self.port)
        await site.start()
Пример #16
0
 async def http_start(self) -> None:
     """
     Used to start the webserver inside the same context as the bot.
     """
     server = web.Server(self._handler)
     runner = web.ServerRunner(server)
     await runner.setup()
     self.site = web.TCPSite(runner, self.IP, self.port)
     await self.site.start()
     self.logger.info(f'Webserver Started on {self.IP}:{self.port}')
Пример #17
0
 async def main():
     app = RemoteDesktopGateway()
     server = web.Server(app.handler)
     runner = web.ServerRunner(server)
     await runner.setup()
     site = web.TCPSite(
         runner, host=host, port=port, ssl_context=sslctx)
     await site.start()
     logger.info('Serving on https://{}:{}/'.format(host, port))
     while True:
         await asyncio.sleep(3600)
Пример #18
0
async def main():
    server = web.Server(accept_client)
    runner = web.ServerRunner(server)
    await runner.setup()
    site = web.TCPSite(runner,
                       CFG.MANAGER_HOST,
                       CFG.MANAGER_PORT,
                       reuse_address=True)
    await site.start()
    print(f"======= Serving on {CFG.MGR_WS_URI} ======")
    await asyncio.sleep(100 * 3600)
Пример #19
0
async def get_server_runner(http_handler):
    """Initialize server runner."""
    aiohttp_server = web.Server(http_handler)
    aiohttp_server_runner = web.ServerRunner(
        aiohttp_server,
        # handle SIGTERM and SIGINT
        # by raising aiohttp.web_runner.GracefulExit exception
        handle_signals=True,
    )
    await aiohttp_server_runner.setup()
    return aiohttp_server_runner
Пример #20
0
    async def listen(self):
        """ Listen and process."""

        self.server = web.Server(self.handler)
        self.runner = web.ServerRunner(self.server)
        await self.runner.setup()
        self.site = web.TCPSite(self.runner, port=self.port)
        await self.site.start()

        while True:
            await asyncio.sleep(10000)
Пример #21
0
    async def run(self) -> None:
        runner = web.ServerRunner(self.server)
        await runner.setup()
        site = web.TCPSite(runner, self.host, self.port)
        self.logger.info("Running HTTP Server %s:%d", self.host, self.port)
        await site.start()

        try:
            await self.manager.wait_finished()
        finally:
            self.logger.info("Closing HTTPServer...")
            await self.server.shutdown()
Пример #22
0
async def main():
    try:
        server = web.Server(handler)
        runner = web.ServerRunner(server)
        await runner.setup()
        site = web.TCPSite(runner=runner,
                           host="localhost",
                           port=PORT,
                           shutdown_timeout=TIMEOUT)
        await site.start()
    except Exception as e:
        error(500, "server exception")
Пример #23
0
async def main():
    proxy = AIOProxy()
    await proxy.create_session()
    server = web.Server(proxy.handler)
    runner = web.ServerRunner(server)
    await runner.setup()
    site = web.TCPSite(runner, 'localhost', 8080)
    await site.start()

    print("======= Serving on http://127.0.0.1:8080/ ======")

    await asyncio.sleep(100*3600)
Пример #24
0
async def main():
    errored = False
    try:
        server = web.Server(handler)
        runner = web.ServerRunner(server)
        await runner.setup()
        host = config_file["web_host"]
        port = config_file["web_port"]
        site = web.TCPSite(runner, host, port)
        await site.start()
        print("======= Serving on http://" + host + ":" + str(port) +
              "/ ======")
    except OSError:
        errored = True
    if errored:
        server = web.Server(handler)
        runner = web.ServerRunner(server)
        await runner.setup()
        site = web.TCPSite(runner, 'localhost', 8080)
        await site.start()
        print("======= Serving on http://127.0.0.1:8080/ ======")
Пример #25
0
async def main():
    server = web.Server(handler)
    runner = web.ServerRunner(server)
    await runner.setup()
    site = web.TCPSite(runner, 'localhost', 8081)
    await site.start()

    print("======= Serving on http://127.0.0.1:8080/ ======")

    # pause here for very long time by serving HTTP requests and
    # waiting for keyboard interruption
    await asyncio.sleep(100 * 3600)
Пример #26
0
    async def run(self):
        """
        run a local HTTP server, listening on the specified port and passing subsequent requests to
        the :meth:`~HttpProxyService.handle_request` of the specified cluster in a round-robin
        fashion
        """
        runner = web.ServerRunner(web.Server(
            self._request_handler))  # type: ignore
        await runner.setup()
        site = web.TCPSite(runner, port=self._port)
        await site.start()

        self._site = site
Пример #27
0
    async def __call__(self):
        server = web.Server(self.router)
        runner = web.ServerRunner(server)
        await runner.setup()
        site = web.TCPSite(runner, self._host, self._port)

        for extension in self.extensions.values():
            await extension(self.services, self.extensions)
        await site.start()
        LOGGER.info('Started HTTPServer on http://%s:%s/', self._host,
                    self._port)
        # Keep running the server until the exit coroutine is used
        await self._exit_event.wait()
Пример #28
0
    async def init_pipe(self, app):
        await BasePipe.init_pipe(self, app)

        if self._direction == 'sender':
            pass
        elif self._direction == 'recipient':
            self._server = web.Server(self._receive)
            self._runner = web.ServerRunner(self._server)
            await self._runner.setup()

            self._site = web.TCPSite(self._runner, self._host, self._port)
            await self._site.start()
        logger.info(
            f'HTTPPipe [{self._app_id}:{self._pipe_id}] - Init complete')
Пример #29
0
async def make_server(handle: typing.Callable[[web.Request],
                                              typing.Awaitable[web.Response]],
                      port: int) -> typing.Tuple[web.Server, web.TCPSite]:
    """
    Make server and start it immidiatly
    :param handle: handler coroutinefunction
    :param port: port on wich server will be started
    :return:
    """
    assert asyncio.iscoroutinefunction(
        handle), 'handle must coroutine function'
    server = web.Server(handle)
    runner = web.ServerRunner(server)
    await runner.setup()
    site = web.TCPSite(runner, 'localhost', port)
    await site.start()
    return server, site
Пример #30
0
    async def startup_server(self) -> web.TCPSite:
        """
        Starts the http server

        Returns:
            the TCP site holding socket information
        """
        server = web.Server(self.http_handler)
        runner = web.ServerRunner(server)
        await runner.setup()
        self.site = web.TCPSite(runner, self.host, self.port)
        await self.site.start()
        self.logging_actor.debug.remote(
            self.worker_id,
            f"======= Serving on http://{self.host}:{self.port}/ ======",
            time.asctime())
        return self.site