feature: add scheduler
This commit is contained in:
@@ -1,10 +1,16 @@
|
||||
from contextlib import asynccontextmanager
|
||||
from fastapi import FastAPI, Request, status
|
||||
from fastapi.responses import JSONResponse
|
||||
from fastapi.concurrency import asynccontextmanager
|
||||
import logging
|
||||
from app.infrastructure.scheduler import process_pending_calls
|
||||
|
||||
from app.api.uis import router as uis_router
|
||||
from app.core.exceptions import CallEventAlreadyExistsError, DatabaseError, ValidationError
|
||||
from apscheduler.schedulers.asyncio import AsyncIOScheduler
|
||||
|
||||
from fastapi import FastAPI
|
||||
import asyncio
|
||||
from app.infrastructure.database import get_db
|
||||
|
||||
# Настройка логирования
|
||||
logging.basicConfig(
|
||||
@@ -13,13 +19,23 @@ logging.basicConfig(
|
||||
)
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@asynccontextmanager
|
||||
async def lifespan(app:FastAPI):
|
||||
scheduler = AsyncIOScheduler()
|
||||
|
||||
scheduler.add_job(process_pending_calls, "interval", seconds = 10)
|
||||
|
||||
scheduler.start()
|
||||
yield
|
||||
await scheduler.shutdown(wait=True)
|
||||
|
||||
app = FastAPI(
|
||||
title="Ingest Service API",
|
||||
description="Микросервис для приема событий звонков",
|
||||
version="1.0.0",
|
||||
lifespan=lifespan
|
||||
)
|
||||
|
||||
|
||||
# Exception handlers
|
||||
@app.exception_handler(CallEventAlreadyExistsError)
|
||||
async def call_event_exists_handler(request: Request, exc: CallEventAlreadyExistsError):
|
||||
|
||||
Reference in New Issue
Block a user