This commit is contained in:
parent
736569930b
commit
5ab5928d12
29
main.py
29
main.py
|
@ -6,20 +6,42 @@ from sentry_sdk.integrations.aiohttp import AioHttpIntegration
|
||||||
from sentry_sdk.integrations.redis import RedisIntegration
|
from sentry_sdk.integrations.redis import RedisIntegration
|
||||||
from sentry_sdk.integrations.sqlalchemy import SqlalchemyIntegration
|
from sentry_sdk.integrations.sqlalchemy import SqlalchemyIntegration
|
||||||
from sentry_sdk.integrations.strawberry import StrawberryIntegration
|
from sentry_sdk.integrations.strawberry import StrawberryIntegration
|
||||||
|
from sqlalchemy import inspect
|
||||||
|
from sqlalchemy.engine.create import create_engine
|
||||||
from starlette.applications import Starlette
|
from starlette.applications import Starlette
|
||||||
from strawberry.asgi import GraphQL
|
from strawberry.asgi import GraphQL
|
||||||
|
from orm.notification import NotificationSeen
|
||||||
|
|
||||||
from resolvers.listener import notifications_worker
|
from resolvers.listener import notifications_worker
|
||||||
|
from resolvers.model import Notification
|
||||||
from resolvers.schema import schema
|
from resolvers.schema import schema
|
||||||
|
from services.db import Base
|
||||||
from services.rediscache import redis
|
from services.rediscache import redis
|
||||||
from settings import DEV_SERVER_PID_FILE_NAME, MODE, SENTRY_DSN
|
from settings import DB_URL, DEV_SERVER_PID_FILE_NAME, MODE, SENTRY_DSN
|
||||||
|
import logging
|
||||||
|
|
||||||
|
|
||||||
|
logging.basicConfig(level=logging.DEBUG)
|
||||||
|
logger = logging.getLogger("\t[main]\t")
|
||||||
|
logger.setLevel(logging.DEBUG)
|
||||||
|
|
||||||
|
|
||||||
async def start_up():
|
async def start_up():
|
||||||
await redis.connect()
|
await redis.connect()
|
||||||
|
|
||||||
|
engine = create_engine(DB_URL)
|
||||||
|
|
||||||
|
# Check if the table already exists
|
||||||
|
inspector = inspect(engine)
|
||||||
|
if not inspector.has_table("notification"):
|
||||||
|
# Create the Notification table
|
||||||
|
Base.metadata.create_all(bind=engine, tables=[Notification.__table__, NotificationSeen.__table__])
|
||||||
|
logger.info("Notification table was created.")
|
||||||
|
else:
|
||||||
|
logger.info("Notification table already exists.")
|
||||||
|
|
||||||
task = asyncio.create_task(notifications_worker())
|
task = asyncio.create_task(notifications_worker())
|
||||||
print(task)
|
logger.info(task)
|
||||||
|
|
||||||
if MODE == "dev":
|
if MODE == "dev":
|
||||||
if exists(DEV_SERVER_PID_FILE_NAME):
|
if exists(DEV_SERVER_PID_FILE_NAME):
|
||||||
|
@ -40,8 +62,7 @@ async def start_up():
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("[sentry] init error")
|
logger.error("sentry init error", e)
|
||||||
print(e)
|
|
||||||
|
|
||||||
|
|
||||||
async def shutdown():
|
async def shutdown():
|
||||||
|
|
|
@ -88,7 +88,8 @@ server {
|
||||||
internal;
|
internal;
|
||||||
}
|
}
|
||||||
|
|
||||||
include /home/dokku/gateway/nginx.conf.d/*.conf;
|
# include /home/dokku/gateway/nginx.conf.d/*.conf;
|
||||||
|
include {{ $.DOKKU_ROOT }}/{{ $.APP }}/nginx.conf.d/*.conf;
|
||||||
}
|
}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,10 @@ import time, json
|
||||||
import strawberry
|
import strawberry
|
||||||
from sqlalchemy.orm import aliased
|
from sqlalchemy.orm import aliased
|
||||||
from sqlalchemy import select, and_
|
from sqlalchemy import select, and_
|
||||||
|
import logging
|
||||||
|
|
||||||
|
logger = logging.getLogger("[resolvers.schema] ")
|
||||||
|
logger.setLevel(logging.DEBUG)
|
||||||
|
|
||||||
|
|
||||||
async def get_notifications_grouped(author_id: int, after: int = 0, limit: int = 10, offset: int = 0):
|
async def get_notifications_grouped(author_id: int, after: int = 0, limit: int = 10, offset: int = 0):
|
||||||
|
@ -61,11 +65,11 @@ async def get_notifications_grouped(author_id: int, after: int = 0, limit: int =
|
||||||
for n, seen in notifications_result:
|
for n, seen in notifications_result:
|
||||||
thread_id = ""
|
thread_id = ""
|
||||||
payload = json.loads(n.payload)
|
payload = json.loads(n.payload)
|
||||||
print(f"[resolvers.schema] {n.action} {n.entity}: {payload}")
|
logger.debug(f"[resolvers.schema] {n.action} {n.entity}: {payload}")
|
||||||
if n.entity == "shout" and n.action == "create":
|
if n.entity == "shout" and n.action == "create":
|
||||||
shout: NotificationShout = payload
|
shout: NotificationShout = payload
|
||||||
thread_id += f"{shout.id}"
|
thread_id += f"{shout.id}"
|
||||||
print(f"[resolvers.schema] create shout: {shout}")
|
logger.debug(f"create shout: {shout}")
|
||||||
group = groups_by_thread.get(thread_id) or NotificationGroup(
|
group = groups_by_thread.get(thread_id) or NotificationGroup(
|
||||||
id=thread_id,
|
id=thread_id,
|
||||||
entity=n.entity,
|
entity=n.entity,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user