Реализованы сервисы ВМ2 - проверка сообщений и синхронизация с Б24 (деплой еще без перевода в боевой режим)

This commit is contained in:
mi
2026-08-13 18:52:42 +03:00
parent 5100ba9fc3
commit 99605b1c77
144 changed files with 15295 additions and 1120 deletions
+7 -10
View File
@@ -138,12 +138,15 @@ async def lifespan(app: FastAPI):
app.state.settings = settings
app.state.db = Database(settings.database_url)
app.state.http = httpx.AsyncClient()
app.state.safety_http = httpx.AsyncClient(
verify=settings.message_safety_ca_file or True
)
app.state.redis = redis.from_url(settings.redis_url, decode_responses=True)
app.state.redis_rt = redis.from_url(settings.redis_realtime_url, decode_responses=True)
app.state.jwks = JWKSValidator(settings, app.state.http)
app.state.rate_limiter = RateLimiter(app.state.redis)
app.state.idempotency = RedisIdempotency(app.state.redis)
app.state.safety = SafetyClient(settings, app.state.http)
app.state.safety = SafetyClient(settings, app.state.safety_http)
app.state.openlines = OpenLinesClient(settings, app.state.http)
app.state.s3 = S3Client(settings)
app.state.realtime = RealtimeFanout(app.state.redis_rt)
@@ -168,6 +171,7 @@ async def lifespan(app: FastAPI):
with suppress(asyncio.CancelledError):
await task
await app.state.http.aclose()
await app.state.safety_http.aclose()
await app.state.redis.aclose()
await app.state.redis_rt.aclose()
await app.state.db.close()
@@ -175,7 +179,7 @@ async def lifespan(app: FastAPI):
telemetry.shutdown()
EXPECTED_API_DB_REVISION = "0010_contact_map_dedup"
EXPECTED_API_DB_REVISION = "0012_safety_v2_checkpoint"
app = FastAPI(
@@ -486,14 +490,7 @@ async def ready(request: Request, db: Session):
except Exception:
components[name] = "failed"
components["jwks"] = "ok" if request.app.state.jwks.has_keys else "failed"
try:
safety_response = await request.app.state.http.get(
f"{str(request.app.state.settings.message_safety_url).rstrip('/')}/health/ready",
timeout=2,
)
components["safety"] = "ok" if safety_response.is_success else "failed"
except httpx.HTTPError:
components["safety"] = "failed"
components["safety"] = "ok" if await request.app.state.safety.ready() else "failed"
components["openlines"] = "ok" if await request.app.state.openlines.ready() else "degraded"
components["s3"] = "ok" if await request.app.state.s3.ready() else "degraded"
critical = {"postgres", "settings", "redis", "jwks", "safety"}