felicity-lims/felicity/lims/boot.py

65 lines
1.6 KiB
Python
Raw Normal View History

2023-08-14 02:08:08 +08:00
from typing import Any
from sanic import Sanic
from sanic_ext import Extend
from sanic.request import Request
from sanic.response import text
from strawberry.sanic.views import GraphQLView
from api.gql.schema import schema
from api.deps import get_auth_context
from api.rest.api_v1 import api
from api.deps import models, get_auth_user
2023-08-26 04:40:56 +08:00
from apps.job.sched import felicity_workforce_init
2023-08-14 02:08:08 +08:00
from core import settings
def register_configs(app: Sanic):
app.config.update(settings.__dict__)
Extend(app)
def register_events(app: Sanic):
2023-08-26 04:40:56 +08:00
@app.listener("after_server_start")
2023-08-14 02:08:08 +08:00
async def setup_db(app):
# app.ctx.db = await db_setup()
2023-08-26 04:40:56 +08:00
# felicity_workforce_init()
...
app.add_task(felicity_workforce_init)
2023-08-14 02:08:08 +08:00
def register_middlewares(app: Sanic):
...
def register_dependencies(app: Sanic):
app.ext.add_dependency(models.User, get_auth_user)
def register_blueprints(app: Sanic):
@app.get("/")
async def index(request):
return text('Hello World')
app.blueprint(api)
def register_graphql(app: Sanic):
class FelicityGraphQLView(GraphQLView):
async def get_context(self, request: Request, response) -> Any:
return await get_auth_context(request)
app.add_route(
FelicityGraphQLView.as_view(schema=schema, graphiql=True),
"/felicity-gql",
)
def register_health(app: Sanic):
...
def register_felicity(app: Sanic):
register_configs(app)
register_events(app)
register_middlewares(app)
register_dependencies(app)
register_blueprints(app)
register_graphql(app)
register_health(app)