forked from pulumi/examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
229 additions
and
1,877 deletions.
There are no files selected for viewing
61 changes: 0 additions & 61 deletions
61
google-native-ts-k8s-python-postgresql/.pre-commit-config.yaml
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
|
||
!/app | ||
!/requirements.txt | ||
!/VERSION.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
0.1.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,17 @@ | ||
from typing import Annotated, AsyncGenerator | ||
from typing import NamedTuple, Protocol | ||
|
||
import asyncpg # type: ignore[import] | ||
from app.config import Config | ||
from xpresso import Depends | ||
|
||
|
||
async def get_pool(config: Config) -> AsyncGenerator[asyncpg.Pool, None]: | ||
# password is optional: | ||
# - cloudsql proxy won't work with it | ||
# - docker run postgres won't work without it | ||
connection_kwargs = dict( | ||
host=config.db_host, | ||
port=config.db_port, | ||
database=config.db_database_name, | ||
user=config.db_username, | ||
) | ||
if config.db_password is not None: | ||
connection_kwargs["password"] = config.db_password.get_secret_value() | ||
async with asyncpg.create_pool(**connection_kwargs) as pool: # type: ignore | ||
yield pool | ||
|
||
|
||
InjectDBConnectionPool = Annotated[asyncpg.Pool, Depends(get_pool, scope="app")] | ||
|
||
|
||
async def get_connection( | ||
pool: InjectDBConnectionPool, | ||
) -> AsyncGenerator[asyncpg.Connection, None]: | ||
async with pool.acquire() as conn: # type: ignore | ||
yield conn | ||
|
||
|
||
InjectDBConnection = Annotated[asyncpg.Connection, Depends(get_connection)] | ||
class ConnectionHealth(Protocol): | ||
async def is_connected(self) -> bool: | ||
... | ||
|
||
|
||
class ConnectionHealth: | ||
def __init__(self, pool: InjectDBConnectionPool) -> None: | ||
self.pool = pool | ||
class PostgresConnectionHealth(NamedTuple): | ||
pool: asyncpg.Pool | ||
|
||
async def is_connected(self) -> bool: | ||
conn: asyncpg.Connection | ||
async with self.pool.acquire() as conn: # type: ignore | ||
return await conn.fetchval("SELECT 1") == 1 # type: ignore | ||
|
||
|
||
def get_db_health(pool: InjectDBConnectionPool) -> ConnectionHealth: | ||
return ConnectionHealth(pool) | ||
|
||
|
||
InjectDBHealth = Annotated[ConnectionHealth, Depends(get_db_health, scope="app")] |
3 changes: 0 additions & 3 deletions
3
google-native-ts-k8s-python-postgresql/app/app/dependencies.py
This file was deleted.
Oops, something went wrong.
11 changes: 0 additions & 11 deletions
11
google-native-ts-k8s-python-postgresql/app/app/lifespan.py
This file was deleted.
Oops, something went wrong.
46 changes: 0 additions & 46 deletions
46
google-native-ts-k8s-python-postgresql/app/app/logconfig.py
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.