5 Commits

Author SHA1 Message Date
a910bffcc9 Update compose.yml
All checks were successful
Build and Push Docker Image / build-and-push (release) Successful in 2m7s
2025-09-15 15:05:35 +03:00
06e24e35e1 Changed 127.0.0.1 to 0.0.0.0
All checks were successful
Build and Push Docker Image / build-and-push (release) Successful in 1m59s
2025-09-15 14:36:54 +03:00
523ac2228d Implemented force exit on connection failure 2025-09-09 17:37:36 +03:00
95a232fb78 Merge branch 'main' of https://git.frik.su/n0one/habr-article-API 2025-09-09 15:24:21 +03:00
355aff8cf3 Table and schema names are now no longer pulled from .env 2025-09-09 15:22:20 +03:00
5 changed files with 10 additions and 8 deletions

View File

@ -8,8 +8,8 @@ services:
DB_NAME: postgres
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
HOST_NAME: "localhost"
PG_PORT: "8000"
HOST_NAME: postgres
PG_PORT: 5432
LOGGING_LEVEL: "INFO"
ENABLE_API_DOCS: "True"
UVI_LOGGING_LEVEL: "info"
@ -27,7 +27,7 @@ services:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
ports:
- "4001:5432"
- :5432
healthcheck:
test: ["CMD", "pg_isready", "-U", "postgres"]
interval: 5s

View File

@ -17,6 +17,7 @@ def set_connection():
logger.info('Connection to PostreSQL DB set successfully')
except psycopg2.Error as e:
logger.error(f'Failed to set connection to the PostgreSQL DB: {e.pgerror}')
exit()
def close_connection(connection):

View File

@ -12,12 +12,15 @@ if config.enable_api_docs:
else:
docs_url = None
schema_name = 'harticle'
table_name = 'articles'
@asynccontextmanager
async def lifespan(app: FastAPI):
DBwork.set_connection()
DBwork.schema_creator(config.schema_name, db.connection)
DBwork.table_creator(config.schema_name, config.table_name, db.connection)
DBwork.schema_creator(schema_name, db.connection)
DBwork.table_creator(schema_name, table_name, db.connection)
yield
DBwork.close_connection(db.connection)

View File

@ -6,8 +6,6 @@ postgres_user = config('POSTGRES_USER')
postgres_password = config('POSTGRES_PASSWORD')
host_name = config('HOST_NAME')
port = config('PG_PORT')
schema_name = config('SCHEMA_NAME')
table_name = config('TABLE_NAME')
enable_api_docs = config('ENABLE_API_DOCS', cast=bool)

View File

@ -5,4 +5,4 @@ from app_creator import create_app
if __name__ == '__main__':
app = create_app()
uvicorn.run(app=app, host="127.0.0.1", port=8000, log_level=uvicorn_logging_level.lower())
uvicorn.run(app=app, host="0.0.0.0", port=8000, log_level=uvicorn_logging_level.lower())