fastfood/manage.py

60 lines
1.3 KiB
Python
Raw Normal View History

import asyncio
2024-02-06 22:07:25 +03:00
import json
2024-01-18 21:15:56 +03:00
import sys
import uvicorn
2024-02-06 22:07:25 +03:00
from fastapi.openapi.utils import get_openapi
2024-01-18 21:15:56 +03:00
2024-02-06 22:07:25 +03:00
from fastfood.app import create_app
from fastfood.repository import create_db_and_tables
2024-01-18 21:15:56 +03:00
2024-02-06 22:07:25 +03:00
def create_openapi():
app = create_app()
with open('openapi.json', 'w') as f:
json.dump(
get_openapi(
title=app.title,
version=app.version,
openapi_version=app.openapi_version,
description=app.description,
routes=app.routes,
contact=app.contact,
license_info=app.license_info,
tags=app.openapi_tags,
),
f,
)
2024-01-18 21:15:56 +03:00
def run_app():
"""
Запуск FastAPI
2024-01-18 21:15:56 +03:00
"""
uvicorn.run(
app='fastfood.app:create_app',
host='0.0.0.0',
2024-01-28 16:22:24 +03:00
port=8000,
2024-01-18 21:15:56 +03:00
reload=True,
factory=True,
2024-01-28 16:22:24 +03:00
workers=1,
2024-01-18 21:15:56 +03:00
)
async def recreate():
"""Удаление и создание таблиц в базе данных для тестирования"""
await create_db_and_tables()
2024-01-18 21:15:56 +03:00
if __name__ == '__main__':
if '--run-server' in sys.argv:
run_app()
if '--run-test-server' in sys.argv:
asyncio.run(recreate())
2024-01-18 21:15:56 +03:00
run_app()
2024-02-06 22:07:25 +03:00
if 'dump' in sys.argv:
create_openapi()