36 lines
985 B
Python
36 lines
985 B
Python
import os
|
|
from importlib import import_module
|
|
from os.path import exists
|
|
|
|
from ariadne import load_schema_from_path, make_executable_schema
|
|
from starlette.applications import Starlette
|
|
|
|
from services.rediscache import redis
|
|
from services.schema import resolvers
|
|
from services.sentry import start_sentry
|
|
from settings import DEV_SERVER_PID_FILE_NAME, MODE
|
|
|
|
import_module("resolvers")
|
|
schema = make_executable_schema(load_schema_from_path("inbox.graphql"), resolvers)
|
|
|
|
|
|
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()))
|
|
print(f"[main] process started in {MODE} mode")
|
|
|
|
|
|
# main starlette app object with ariadne mounted in root
|
|
app = Starlette(
|
|
on_startup=[
|
|
redis.connect,
|
|
start_sentry,
|
|
start,
|
|
],
|
|
on_shutdown=[redis.disconnect],
|
|
debug=True,
|
|
)
|