resolvers-updates
Some checks failed
deploy / deploy (push) Failing after 1m30s

This commit is contained in:
2023-12-16 18:24:30 +03:00
parent bf7bc03e50
commit 692dd9cfe0
7 changed files with 171 additions and 34 deletions

21
main.py
View File

@@ -4,6 +4,7 @@ from importlib import import_module
from os.path import exists
from ariadne import load_schema_from_path, make_executable_schema
from ariadne.asgi import GraphQL
from sqlalchemy.exc import IntegrityError
from sentry_sdk.integrations.ariadne import AriadneIntegration
from sentry_sdk.integrations.redis import RedisIntegration
from sentry_sdk.integrations.sqlalchemy import SqlalchemyIntegration
@@ -58,25 +59,5 @@ async def shutdown():
await redis.disconnect()
class WebhookEndpoint(HTTPEndpoint):
async def post(self, request: Request) -> JSONResponse:
try:
data = await request.json()
if data:
auth = request.headers.get("Authorization")
if auth:
if auth == os.environ.get("WEBHOOK_SECRET"):
user_id: str = data["user"]["id"]
slug: str = data["user"]["email"].split("@")[0]
slug: str = re.sub("[^0-9a-z]+", "-", slug.lower())
await create_author(user_id, slug)
return JSONResponse({"status": "success"})
except Exception as e:
import traceback
traceback.print_exc()
return JSONResponse({"status": "error", "message": str(e)}, status_code=500)
routes = [Route("/", GraphQL(schema, debug=True)), Route("/new-author", WebhookEndpoint)]
app = Starlette(routes=routes, debug=True, on_startup=[start_up], on_shutdown=[shutdown])