Beispiel #1
0
async def _init_nosql_dbs(app: web.Application) -> web.Application:
    """
    Wrapper over initializing dbase.

    :param app: an instance of aiohttp application.
    :return: an instance of aiohttp application with updates.
    """
    ###
    # Create connection to databases
    NoSQLDatabases = type(
        'NoSQLDatabases', (SimpleNamespace,), {'mongo': None, 'influx': None}
    )
    app.dbs = NoSQLDatabases()

    cfg = deep_get(app.shared.extras, 'dbs.mongo',  {})
    app.dbs.mongo  = MongosDBClient(**cfg, loop=app.loop)

    cfg = deep_get(app.shared.extras, 'dbs.influx', {})
    app.dbs.influx = InfluxDBClient(**cfg, loop=app.loop)

    aws: Tuple[
         Union[Awaitable[_Returns_co], Callable[..., _Returns_co]], ...] = (
            app.dbs.mongo.ping(), app.dbs.influx.ping(),
    )
    pings = await asyncio.gather(*aws, loop=app.loop, return_exceptions=True)

    ###
    # Attention! I apologize in advance, but the code that was in this place I had
    # to remove that it would be completely not to violate NDA.
    # ¯\_(ツ)_/¯
    # Thanks for understanding!

    return app