async+fmt-fix
All checks were successful
Deploy on push / deploy (push) Successful in 1m12s

This commit is contained in:
2024-10-14 12:19:30 +03:00
parent 4e7fb953ba
commit 3188a67661
5 changed files with 73 additions and 51 deletions

56
main.py
View File

@@ -6,11 +6,20 @@ from os.path import exists
from ariadne import load_schema_from_path, make_executable_schema
from ariadne.asgi import GraphQL
from starlette.applications import Starlette
from starlette.routing import Route
from starlette.responses import JSONResponse
from starlette.routing import Route
from cache.precache import precache_data
from cache.revalidator import revalidation_manager
from orm import ( # , collection, invite
author,
community,
notification,
reaction,
shout,
topic,
)
from services.db import create_table_if_not_exists, engine
from services.exception import ExceptionHandlerMiddleware
from services.redis import redis
from services.schema import resolvers
@@ -18,8 +27,6 @@ from services.search import search_service
from services.viewed import ViewedStorage
from services.webhook import WebhookEndpoint
from settings import DEV_SERVER_PID_FILE_NAME, MODE
from services.db import engine, create_table_if_not_exists
from orm import author, notification, shout, topic, reaction, community #, collection, invite
import_module("resolvers")
schema = make_executable_schema(load_schema_from_path("schema/"), resolvers)
@@ -34,10 +41,37 @@ async def start():
print(f"[main] process started in {MODE} mode")
def create_all_tables():
for model in [
author.Author,
author.AuthorRating,
author.AuthorFollower,
notification.Notification,
notification.NotificationSeen,
shout.Shout,
shout.ShoutAuthor,
shout.ShoutTopic,
shout.ShoutCommunity,
topic.Topic,
topic.TopicFollower,
reaction.Reaction,
community.Community,
community.CommunityFollower,
# collection.Collection, collection.ShoutCollection,
# invite.Invite
]:
create_table_if_not_exists(engine, model)
async def create_all_tables_async():
# Оборачиваем синхронную функцию в асинхронную
await asyncio.to_thread(create_all_tables)
async def lifespan(app):
# Запуск всех сервисов при старте приложения
await asyncio.gather(
create_all_tables(),
create_all_tables_async(),
redis.connect(),
precache_data(),
ViewedStorage.init(),
@@ -50,22 +84,10 @@ async def lifespan(app):
await redis.disconnect()
def create_all_tables():
for model in [author.Author, author.AuthorRating, author.AuthorFollower,
notification.Notification, notification.NotificationSeen,
shout.Shout, shout.ShoutAuthor, shout.ShoutTopic, shout.ShoutCommunity,
topic.Topic, topic.TopicFollower,
reaction.Reaction,
community.Community, community.CommunityFollower,
# collection.Collection, collection.ShoutCollection,
# invite.Invite
]:
create_table_if_not_exists(engine, model)
# Создаем экземпляр GraphQL
graphql_app = GraphQL(schema, debug=True)
# Оборачиваем GraphQL-обработчик для лучшей обработки ошибок
async def graphql_handler(request):
try: