mirror of
https://github.com/dograh-hq/dograh.git
synced 2026-06-13 08:15:21 +02:00
chore: remove old files
This commit is contained in:
parent
c711920165
commit
1349654c75
23 changed files with 6 additions and 4198 deletions
37
api/app.py
37
api/app.py
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
import sentry_sdk
|
||||
|
||||
from api.constants import DEPLOYMENT_MODE, ENABLE_TELEMETRY, REDIS_URL, SENTRY_DSN
|
||||
from api.constants import DEPLOYMENT_MODE, ENABLE_TELEMETRY, SENTRY_DSN
|
||||
from api.logging_config import ENVIRONMENT, setup_logging
|
||||
|
||||
# Set up logging and get the listener for cleanup
|
||||
|
|
@ -21,62 +21,27 @@ if SENTRY_DSN and (
|
|||
|
||||
|
||||
from contextlib import asynccontextmanager
|
||||
from typing import Optional
|
||||
|
||||
import redis.asyncio as aioredis
|
||||
from fastapi import APIRouter, FastAPI
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from loguru import logger
|
||||
|
||||
from api.routes.main import router as main_router
|
||||
from api.services.telephony.worker_event_subscriber import (
|
||||
WorkerEventSubscriber,
|
||||
setup_worker_subscriber,
|
||||
)
|
||||
from api.tasks.arq import get_arq_redis
|
||||
|
||||
API_PREFIX = "/api/v1"
|
||||
|
||||
# Global reference to worker subscriber for graceful shutdown
|
||||
worker_subscriber_instance: Optional[WorkerEventSubscriber] = None
|
||||
|
||||
|
||||
@asynccontextmanager
|
||||
async def lifespan(app: FastAPI):
|
||||
global worker_subscriber_instance
|
||||
|
||||
# warmup arq pool
|
||||
await get_arq_redis()
|
||||
|
||||
# Setup Redis connection for distributed mode
|
||||
redis = await aioredis.from_url(REDIS_URL, decode_responses=True)
|
||||
|
||||
# Setup worker subscriber (ARI Manager runs separately)
|
||||
worker_subscriber = await setup_worker_subscriber(redis)
|
||||
worker_subscriber_instance = worker_subscriber
|
||||
|
||||
# Store worker ID in app state for health check
|
||||
app.state.worker_id = worker_subscriber.worker_id
|
||||
app.state.worker_subscriber = worker_subscriber
|
||||
|
||||
yield # Run app
|
||||
|
||||
# Shutdown sequence - this runs when FastAPI is shutting down
|
||||
logger.info("Starting graceful shutdown...")
|
||||
|
||||
# First, try graceful shutdown with timeout
|
||||
if worker_subscriber:
|
||||
try:
|
||||
# Check if we should do graceful shutdown (e.g., if SIGTERM was received)
|
||||
# For now, we'll attempt graceful shutdown for all shutdowns
|
||||
await worker_subscriber.graceful_shutdown(max_wait_seconds=300)
|
||||
except Exception as e:
|
||||
logger.error(f"Error during graceful shutdown: {e}")
|
||||
# Fall back to immediate stop
|
||||
await worker_subscriber.stop()
|
||||
|
||||
await redis.aclose()
|
||||
|
||||
|
||||
app = FastAPI(
|
||||
title="Dograh API",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue