Ejemplo n.º 1
0
async def triopg_conn(request, asyncio_loop, postgresql_connection_specs):
    if request.param == "from_connect":
        async with triopg.connect(**postgresql_connection_specs) as conn:
            yield conn

    else:
        async with triopg.create_pool(**postgresql_connection_specs) as pool:
            async with pool.acquire() as conn:
                yield conn
Ejemplo n.º 2
0
async def test_triopg_pool(asyncio_loop, asyncpg_conn,
                           postgresql_connection_specs):
    async with triopg.create_pool(**postgresql_connection_specs) as pool:
        async with pool.acquire() as conn:
            await execute_queries(conn, asyncpg_conn)

    with pytest.raises(triopg.InterfaceError):
        async with pool.acquire() as conn:
            pass
Ejemplo n.º 3
0
 async def _run_connections(self, task_status=trio.TASK_STATUS_IGNORED):
     async with triopg.create_pool(
         self.url, min_size=self.min_connections, max_size=self.max_connections
     ) as self.pool:
         # This connection is dedicated to the notifications listening, so it
         # would only complicate stuff to include it into the connection pool
         async with triopg.connect(self.url) as self.notification_conn:
             await self.notification_conn.add_listener("app_notification", self._on_notification)
             task_status.started()
             await trio.sleep_forever()
Ejemplo n.º 4
0
    async def _run_connections(self, started_cb):
        async with triopg.create_pool(self.url) as self.pool:
            async with self.pool.acquire() as conn:
                if not await _is_db_initialized(conn):
                    raise RuntimeError("Database not initialized !")
            # This connection is dedicated to the notifications listening, so it
            # would only complicate stuff to include it into the connection pool
            async with triopg.connect(self.url) as self.notification_conn:
                await self.notification_conn.add_listener(
                    "app_notification", self._on_notification)

                await started_cb()
Ejemplo n.º 5
0
 async def _retryable(self,
                      task_status,
                      postgres_initial_connect_failed=False):
     async with triopg.create_pool(
             self.url,
             min_size=self.min_connections,
             max_size=self.max_connections) as self.pool:
         # This connection is dedicated to the notifications listening, so it
         # would only complicate stuff to include it into the connection pool
         async with triopg.connect(self.url) as self.notification_conn:
             await self.notification_conn.add_listener(
                 "app_notification", self._on_notification)
             task_status.started()
             if postgres_initial_connect_failed:
                 logger.warning(
                     "db connection established after initial failure")
             await trio.sleep_forever()
Ejemplo n.º 6
0
    async def _run_connections(self, task_status=trio.TASK_STATUS_IGNORED):

        async with triopg.create_pool(
                self.url,
                min_size=self.min_connections,
                max_size=self.max_connections) as self.pool:
            # This connection is dedicated to the notifications listening, so it
            # would only complicate stuff to include it into the connection pool
            async with triopg.connect(self.url) as self.notification_conn:
                self.notification_conn.add_termination_listener(
                    self._on_notification_conn_termination)
                await self.notification_conn.add_listener(
                    "app_notification", self._on_notification)
                task_status.started()
                try:
                    await trio.sleep_forever()
                finally:
                    if self._connection_lost:
                        raise ConnectionError(
                            "PostgreSQL notification query has been lost")
Ejemplo n.º 7
0
async def triopg_pool(asyncio_loop, postgresql_connection_specs):
    async with triopg.create_pool(**postgresql_connection_specs) as pool:
        yield pool