CI / UI Checks (pull_request) Successful in 8s
CI / Rust Checks (pull_request) Successful in 19m34s
CI / Rust Feature Validation (pull_request) Skipped
CI / Frontend E2E (pull_request) Skipped
CI / Community Image Smoke (pull_request) Skipped
CI / Required Checks (pull_request) Successful in 1s
CI / Deploy (pull_request) Skipped
Application entry выдаёт Task ID только после атомарного PostgreSQL commit Task+intent+capacity; replay/conflict, owner scope, bounded envelope, terminal CAS и fail-closed readiness проверены на реальном PG. Также включён принятый план перехода на rmcp (только документ, миграция не запускается).
89 lines
3.0 KiB
Rust
89 lines
3.0 KiB
Rust
use std::time::Duration;
|
|
|
|
use sqlx::{
|
|
AssertSqlSafe, PgPool,
|
|
postgres::{PgConnectOptions, PgPoolOptions},
|
|
};
|
|
|
|
use crate::{MigrationAuthority, error::RegistryError};
|
|
|
|
use super::{PostgresPoolConfig, PostgresRegistry};
|
|
|
|
impl PostgresRegistry {
|
|
pub async fn connect(database_url: &str) -> Result<Self, RegistryError> {
|
|
Self::connect_in_schema(database_url, None).await
|
|
}
|
|
|
|
pub async fn connect_with_options(
|
|
connect_options: PgConnectOptions,
|
|
) -> Result<Self, RegistryError> {
|
|
Self::connect_with_options_and_pool_config(connect_options, PostgresPoolConfig::default())
|
|
.await
|
|
}
|
|
|
|
pub async fn connect_with_options_and_pool_config(
|
|
connect_options: PgConnectOptions,
|
|
pool_config: PostgresPoolConfig,
|
|
) -> Result<Self, RegistryError> {
|
|
let pool = PgPoolOptions::new()
|
|
.max_connections(pool_config.max_connections)
|
|
.min_connections(pool_config.min_connections)
|
|
.acquire_timeout(Duration::from_millis(pool_config.acquire_timeout_ms))
|
|
.idle_timeout(Duration::from_millis(pool_config.idle_timeout_ms))
|
|
.max_lifetime(Duration::from_millis(pool_config.max_lifetime_ms))
|
|
.connect_with(connect_options)
|
|
.await?;
|
|
MigrationAuthority::require_current(&pool).await?;
|
|
Ok(Self { pool })
|
|
}
|
|
|
|
pub fn pool(&self) -> &PgPool {
|
|
&self.pool
|
|
}
|
|
|
|
pub async fn ping(&self) -> Result<(), RegistryError> {
|
|
sqlx::query("select 1").execute(&self.pool).await?;
|
|
Ok(())
|
|
}
|
|
|
|
/// Readiness probe of the mandatory execution-admission state (Story 4.1). A missing or
|
|
/// unreadable admission schema is a dependency failure, never a degraded-but-ready state.
|
|
pub async fn execution_admission_health(&self) -> Result<(), crank_core::AdmissionStoreError> {
|
|
super::admission::admission_health(&self.pool).await
|
|
}
|
|
|
|
/// Readiness probe of the durable Task state (Story 4.2).
|
|
pub async fn durable_tasks_health(&self) -> Result<(), crank_core::TaskError> {
|
|
super::tasks::tasks_health(&self.pool).await
|
|
}
|
|
|
|
/// Authoritative admission queue readings for low-cardinality metrics.
|
|
pub async fn execution_admission_snapshot(
|
|
&self,
|
|
) -> Result<crank_core::AdmissionQueueSnapshot, crank_core::AdmissionStoreError> {
|
|
super::admission::admission_snapshot(&self.pool).await
|
|
}
|
|
|
|
async fn connect_in_schema(
|
|
database_url: &str,
|
|
schema: Option<&str>,
|
|
) -> Result<Self, RegistryError> {
|
|
let pool = PgPoolOptions::new()
|
|
.min_connections(0)
|
|
.max_connections(1)
|
|
.idle_timeout(std::time::Duration::from_secs(1))
|
|
.connect(database_url)
|
|
.await?;
|
|
|
|
if let Some(schema) = schema {
|
|
sqlx::query(AssertSqlSafe(format!("set search_path to {schema}")))
|
|
.execute(&pool)
|
|
.await?;
|
|
}
|
|
|
|
let registry = Self { pool };
|
|
MigrationAuthority::require_current(®istry.pool).await?;
|
|
Ok(registry)
|
|
}
|
|
}
|