feat: blank taskiq setup
This commit is contained in:
19
main.py
19
main.py
@ -1,3 +1,6 @@
|
||||
import contextlib
|
||||
|
||||
import taskiq_fastapi
|
||||
from fastapi import FastAPI, Request
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from fastapi.middleware.gzip import GZipMiddleware
|
||||
@ -6,15 +9,29 @@ from fastapi.staticfiles import StaticFiles
|
||||
from starlette.responses import JSONResponse
|
||||
|
||||
import routers
|
||||
from task_management import broker
|
||||
from utils.auto_include_routers import auto_include_routers
|
||||
from utils.exceptions import *
|
||||
|
||||
origins = ["http://localhost:3000"]
|
||||
|
||||
|
||||
@contextlib.asynccontextmanager
|
||||
async def lifespan(app):
|
||||
if not broker.is_worker_process:
|
||||
await broker.startup()
|
||||
|
||||
yield
|
||||
|
||||
if not broker.is_worker_process:
|
||||
await broker.shutdown()
|
||||
|
||||
|
||||
app = FastAPI(
|
||||
separate_input_output_schemas=True,
|
||||
default_response_class=ORJSONResponse,
|
||||
root_path="/api",
|
||||
# lifespan=lifespan,
|
||||
)
|
||||
|
||||
app.add_middleware(
|
||||
@ -29,6 +46,8 @@ app.add_middleware(
|
||||
minimum_size=1_000,
|
||||
)
|
||||
|
||||
taskiq_fastapi.init(broker, "main:app")
|
||||
|
||||
|
||||
@app.exception_handler(ObjectNotFoundException)
|
||||
async def not_found_exception_handler(request: Request, exc: ObjectNotFoundException):
|
||||
|
||||
Reference in New Issue
Block a user