2023-11-22 17:13:16 +08:00
|
|
|
from fastapi import FastAPI
|
|
|
|
from strawberry.fastapi import GraphQLRouter
|
2023-09-11 13:02:05 +08:00
|
|
|
|
2023-08-14 02:08:08 +08:00
|
|
|
from api.gql.schema import schema
|
|
|
|
from api.rest.api_v1 import api
|
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
|
2023-11-22 17:13:16 +08:00
|
|
|
from init import initialize_felicity
|
|
|
|
from views import setup_webapp
|
|
|
|
|
|
|
|
|
|
|
|
def register_routes(app: FastAPI):
|
|
|
|
@app.get("/health")
|
|
|
|
async def get_health(request):
|
|
|
|
return {"up": True}
|
2023-08-14 02:08:08 +08:00
|
|
|
|
2023-11-22 17:13:16 +08:00
|
|
|
app.include_router(api, prefix="/api/v1")
|
|
|
|
setup_webapp(app, settings.SERVE_WEBAPP)
|
2023-08-14 02:08:08 +08:00
|
|
|
|
2023-09-11 13:02:05 +08:00
|
|
|
|
2023-11-22 17:13:16 +08:00
|
|
|
def register_websockets(app: FastAPI):
|
|
|
|
...
|
2023-08-26 04:53:40 +08:00
|
|
|
|
2023-08-14 02:08:08 +08:00
|
|
|
|
2023-11-22 17:13:16 +08:00
|
|
|
def register_listeners(app: FastAPI):
|
|
|
|
@app.on_event("startup")
|
|
|
|
async def init_seeds():
|
|
|
|
if settings.LOAD_SETUP_DATA:
|
|
|
|
await initialize_felicity()
|
2023-08-26 04:53:40 +08:00
|
|
|
|
2023-09-11 13:02:05 +08:00
|
|
|
|
2023-11-22 17:13:16 +08:00
|
|
|
def register_graphql(app: FastAPI):
|
|
|
|
graphql_app = GraphQLRouter(schema, graphiql=True)
|
|
|
|
app.include_router(graphql_app, prefix="/felicity-gql")
|
2023-09-11 13:02:05 +08:00
|
|
|
|
2023-11-22 17:13:16 +08:00
|
|
|
# class FelicityGraphQLView(GraphQLView):
|
|
|
|
# async def get_context(self, request: Request, response) -> Any:
|
|
|
|
# return await get_gql_context(request, response)
|
|
|
|
#
|
|
|
|
# app.add_route(
|
|
|
|
# FelicityGraphQLView.as_view(schema=schema, graphiql=True),
|
|
|
|
# "/felicity-gql",
|
|
|
|
# )
|
2023-09-11 13:02:05 +08:00
|
|
|
|
2023-08-14 02:08:08 +08:00
|
|
|
|
2023-11-22 17:13:16 +08:00
|
|
|
def register_tasks(app: FastAPI):
|
|
|
|
# bg_tasks = BackgroundTasks(tasks=None)
|
|
|
|
# bg_tasks.add_task(felicity_workforce_init)
|
|
|
|
felicity_workforce_init()
|
2023-08-14 02:08:08 +08:00
|
|
|
|
|
|
|
|
2023-11-22 17:13:16 +08:00
|
|
|
def register_felicity(app: FastAPI):
|
|
|
|
register_routes(app)
|
|
|
|
register_websockets(app)
|
2023-08-14 02:08:08 +08:00
|
|
|
register_graphql(app)
|
2023-11-22 17:13:16 +08:00
|
|
|
register_listeners(app)
|
|
|
|
register_tasks(app)
|