2023-01-17 22:07:44 +01:00
|
|
|
import os
|
2022-09-03 13:50:14 +03:00
|
|
|
from importlib import import_module
|
2022-11-23 00:51:29 +01:00
|
|
|
from os.path import exists
|
2023-12-17 23:30:20 +03:00
|
|
|
|
2024-02-19 11:58:02 +03:00
|
|
|
from ariadne import load_schema_from_path, make_executable_schema
|
2022-09-03 13:50:14 +03:00
|
|
|
from ariadne.asgi import GraphQL
|
|
|
|
from starlette.applications import Starlette
|
2023-11-29 00:19:33 +03:00
|
|
|
from starlette.routing import Route
|
2023-11-28 22:07:53 +03:00
|
|
|
|
2023-10-23 17:47:11 +03:00
|
|
|
from services.rediscache import redis
|
2024-02-19 14:45:55 +03:00
|
|
|
from services.schema import resolvers
|
2024-01-29 06:45:07 +03:00
|
|
|
from services.search import search_service
|
2023-12-22 12:09:24 +03:00
|
|
|
from services.viewed import ViewedStorage
|
2024-02-02 15:03:44 +03:00
|
|
|
from services.webhook import WebhookEndpoint
|
2024-02-16 12:34:39 +03:00
|
|
|
from settings import DEV_SERVER_PID_FILE_NAME, MODE
|
2024-01-25 22:41:27 +03:00
|
|
|
|
|
|
|
import_module('resolvers')
|
2024-02-19 11:58:02 +03:00
|
|
|
schema = make_executable_schema(load_schema_from_path('schema/'), resolvers)
|
|
|
|
|
2022-09-03 13:50:14 +03:00
|
|
|
|
2024-02-19 10:14:14 +03:00
|
|
|
async def start():
|
|
|
|
if MODE == 'development':
|
|
|
|
if not exists(DEV_SERVER_PID_FILE_NAME):
|
|
|
|
# pid file management
|
|
|
|
with open(DEV_SERVER_PID_FILE_NAME, 'w', encoding='utf-8') as f:
|
|
|
|
f.write(str(os.getpid()))
|
2024-02-16 12:40:41 +03:00
|
|
|
print(f'[main] process started in {MODE} mode')
|
2022-09-03 13:50:14 +03:00
|
|
|
|
2024-02-16 12:40:41 +03:00
|
|
|
# main starlette app object with ariadne mounted in root
|
|
|
|
app = Starlette(
|
|
|
|
routes=[
|
|
|
|
Route('/', GraphQL(schema, debug=True)),
|
|
|
|
Route('/new-author', WebhookEndpoint),
|
|
|
|
],
|
|
|
|
on_startup=[
|
2024-02-16 12:34:39 +03:00
|
|
|
redis.connect,
|
|
|
|
ViewedStorage.init,
|
|
|
|
search_service.info,
|
2024-02-20 17:54:43 +03:00
|
|
|
# start_sentry,
|
2024-02-19 10:14:14 +03:00
|
|
|
start
|
2024-02-16 12:40:41 +03:00
|
|
|
],
|
|
|
|
on_shutdown=[
|
|
|
|
redis.disconnect
|
|
|
|
],
|
|
|
|
debug=True
|
|
|
|
)
|