granian+precommit
This commit is contained in:
20
main.py
20
main.py
@@ -4,7 +4,6 @@ from os.path import exists
|
||||
|
||||
from ariadne import load_schema_from_path, make_executable_schema
|
||||
from ariadne.asgi import GraphQL
|
||||
|
||||
from sentry_sdk.integrations.aiohttp import AioHttpIntegration
|
||||
from sentry_sdk.integrations.ariadne import AriadneIntegration
|
||||
from sentry_sdk.integrations.redis import RedisIntegration
|
||||
@@ -16,28 +15,29 @@ from starlette.routing import Route
|
||||
from resolvers.webhook import WebhookEndpoint
|
||||
from services.rediscache import redis
|
||||
from services.schema import resolvers
|
||||
from settings import DEV_SERVER_PID_FILE_NAME, MODE, SENTRY_DSN
|
||||
from services.viewed import ViewedStorage
|
||||
from settings import DEV_SERVER_PID_FILE_NAME, MODE, SENTRY_DSN
|
||||
|
||||
import_module("resolvers")
|
||||
schema = make_executable_schema(load_schema_from_path("schemas/core.graphql"), resolvers) # type: ignore
|
||||
|
||||
import_module('resolvers')
|
||||
schema = make_executable_schema(load_schema_from_path('schemas/core.graphql'), resolvers) # type: ignore
|
||||
|
||||
|
||||
async def start_up():
|
||||
print(f"[main] starting in {MODE} mode")
|
||||
print(f'[main] starting in {MODE} mode')
|
||||
|
||||
await redis.connect()
|
||||
|
||||
# start viewed service
|
||||
await ViewedStorage.init()
|
||||
|
||||
if MODE == "development":
|
||||
if MODE == 'development':
|
||||
# pid file management
|
||||
if not exists(DEV_SERVER_PID_FILE_NAME):
|
||||
with open(DEV_SERVER_PID_FILE_NAME, "w", encoding="utf-8") as f:
|
||||
with open(DEV_SERVER_PID_FILE_NAME, 'w', encoding='utf-8') as f:
|
||||
f.write(str(os.getpid()))
|
||||
|
||||
if MODE == "production":
|
||||
if MODE == 'production':
|
||||
# sentry monitoring
|
||||
try:
|
||||
import sentry_sdk
|
||||
@@ -54,7 +54,7 @@ async def start_up():
|
||||
],
|
||||
)
|
||||
except Exception as e:
|
||||
print("[sentry] init error")
|
||||
print('[sentry] init error')
|
||||
print(e)
|
||||
|
||||
|
||||
@@ -62,5 +62,5 @@ async def shutdown():
|
||||
await redis.disconnect()
|
||||
|
||||
|
||||
routes = [Route("/", GraphQL(schema, debug=True)), Route("/new-author", WebhookEndpoint)]
|
||||
routes = [Route('/', GraphQL(schema, debug=True)), Route('/new-author', WebhookEndpoint)]
|
||||
app = Starlette(routes=routes, debug=True, on_startup=[start_up], on_shutdown=[shutdown])
|
||||
|
Reference in New Issue
Block a user