notifier/main.py
Untone e942d82412
All checks were successful
Deploy to v2 / deploy (push) Successful in 2m9s
merged
2024-02-18 10:47:07 +03:00

59 lines
1.7 KiB
Python

import asyncio
import logging
import os
from os.path import exists
from sentry_sdk.integrations.aiohttp import AioHttpIntegration
from sentry_sdk.integrations.redis import RedisIntegration
from sentry_sdk.integrations.sqlalchemy import SqlalchemyIntegration
from sentry_sdk.integrations.strawberry import StrawberryIntegration
from starlette.applications import Starlette
from strawberry.asgi import GraphQL
from resolvers.listener import notifications_worker
from resolvers.schema import schema
from services.rediscache import redis
from settings import DEV_SERVER_PID_FILE_NAME, MODE, SENTRY_DSN
logger = logging.getLogger("\t[main]\t")
logger.setLevel(logging.DEBUG)
async def start_up():
logger.info("[main] starting...")
await redis.connect()
task = asyncio.create_task(notifications_worker())
logger.info(task)
if MODE == "dev":
if exists(DEV_SERVER_PID_FILE_NAME):
with open(DEV_SERVER_PID_FILE_NAME, "w", encoding="utf-8") as f:
f.write(str(os.getpid()))
else:
logger.info("[main] production mode")
try:
import sentry_sdk
sentry_sdk.init(
SENTRY_DSN,
enable_tracing=True,
integrations=[
StrawberryIntegration(async_execution=True),
SqlalchemyIntegration(),
RedisIntegration(),
AioHttpIntegration(),
],
)
except Exception as e:
logger.error("sentry init error", e)
async def shutdown():
await redis.disconnect()
app = Starlette(debug=True, on_startup=[start_up], on_shutdown=[shutdown])
app.mount("/", GraphQL(schema, debug=True))