notifier/main.py
Untone e22d5468ab
All checks were successful
deploy / deploy (push) Successful in 1m11s
0.1.0-fixes
2023-12-22 12:09:03 +03:00

53 lines
1.5 KiB
Python

import asyncio
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
async def start_up():
await redis.connect()
task = asyncio.create_task(notifications_worker())
print(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:
try:
import sentry_sdk
sentry_sdk.init(
SENTRY_DSN,
enable_tracing=True,
integrations=[
StrawberryIntegration(async_execution=True),
SqlalchemyIntegration(),
RedisIntegration(),
AioHttpIntegration(),
],
)
except Exception as e:
print("[sentry] init error")
print(e)
async def shutdown():
await redis.disconnect()
app = Starlette(debug=True, on_startup=[start_up], on_shutdown=[shutdown])
app.mount("/", GraphQL(schema, debug=True))