Spaces:
Paused
Paused
dushyantsingh0 commited on
Commit ·
17bb84f
1
Parent(s): 22ea2a1
Beta 1.0: Startup Resiliency (Fix Arq Type + DB Secret Logic)
Browse filesFiles changed (3)
- core/config.py+14-3
- main.py+7
- nexus_worker.py+3-4
28 unmodified lines293031323334353637383940414228 unmodified lines@propertydef async_database_url(self) -> str:"""Constructs or ensures the +asyncpg prefix exists for SQLAlchemy."""if self.DATABASE_URL:url = self.DATABASE_URLif url.startswith("postgresql://"):return url.replace("postgresql://", "postgresql+asyncpg://", 1)return url# Construct from components if DATABASE_URL is missingreturn f"postgresql+asyncpg://{self.DB_USER}:{self.DB_PASS}@{self.DB_HOST}:{self.DB_PORT}/{self.DB_NAME}"REDIS_URL: str = "redis://localhost:6379"28 unmodified lines2930313233343536373839404142434445464748495051525328 unmodified lines@propertydef async_database_url(self) -> str:"""Constructs or ensures the +asyncpg prefix exists for SQLAlchemy."""# Priority: Explicit environment variable DATABASE_URLurl = self.DATABASE_URLif url:if url.startswith("postgresql://"):return url.replace("postgresql://", "postgresql+asyncpg://", 1)return url# Fallback: Construct from individual partsreturn f"postgresql+asyncpg://{self.DB_USER}:{self.DB_PASS}@{self.DB_HOST}:{self.DB_PORT}/{self.DB_NAME}"@propertydef database_host(self) -> str:"""Returns the hostname of the database for diagnostic logs."""if self.DATABASE_URL:try:from urllib.parse import urlparsereturn urlparse(self.DATABASE_URL).hostname or "unspecified"except: return "error-parsing"return self.DB_HOSTREDIS_URL: str = "redis://localhost:6379"
7 unmodified lines891011121314151617181920217 unmodified lines# Initialize global loggingsetup_logging()settings = get_settings()@asynccontextmanagerasync def lifespan(app: FastAPI):# Startup: ensure tables and schema versioning are up to date via Alembicawait run_migrations()yieldawait engine.dispose()app = FastAPI(7 unmodified lines89101112131415161718192021222324252627287 unmodified lines# Initialize global loggingsetup_logging()logger = get_logger(__name__)settings = get_settings()@asynccontextmanagerasync def lifespan(app: FastAPI):# Startup diagnosticslogger.info("Starting Nexus Gateway (Beta 1.0)")logger.info(f"Target Database Host: {settings.database_host}")# Startup: ensure tables and schema versioning are up to date via Alembicawait run_migrations()yield# Shutdownlogger.info("Shutting down Nexus Gateway")await engine.dispose()app = FastAPI(
49 unmodified lines5051525354555657585949 unmodified lines# )# ---------------------------# Priority Management: Listen to all queues by default for consolidated beta hosting# To isolate: `export QUEUE=arq:critical`_raw_queue = os.getenv("QUEUE", "arq:queue,arq:critical,arq:ai")queue_name = [q.strip() for q in _raw_queue.split(",")] if "," in _raw_queue else _raw_queue# List of functions to register for background executionfunctions = [49 unmodified lines50515253545556575849 unmodified lines# )# ---------------------------# Priority Management: Unified queue for Beta stability# Arq requires a string for queue_name to handle internal health-check keysqueue_name = os.getenv("QUEUE", "arq:queue")# List of functions to register for background executionfunctions = [
core/config.py+14-3
main.py+7
nexus_worker.py+3-4