refactor: adapters configured from config crate

This commit is contained in:
2026-10-25 21:07:19 +01:00
parent 1f724bb064
commit 04f9c13625
45 changed files with 277 additions and 177 deletions

View File

@@ -22,20 +22,11 @@ pub struct DbEventQueueConfig {
}
impl DbEventQueueConfig {
pub fn from_env() -> Self {
pub fn from_config(config: &config::EventsConfig) -> Self {
Self {
poll_interval_ms: std::env::var("EVENT_QUEUE_POLL_INTERVAL_MS")
.ok()
.and_then(|v| v.parse().ok())
.unwrap_or(500),
batch_size: std::env::var("EVENT_QUEUE_BATCH_SIZE")
.ok()
.and_then(|v| v.parse().ok())
.unwrap_or(10),
max_attempts: std::env::var("EVENT_QUEUE_MAX_ATTEMPTS")
.ok()
.and_then(|v| v.parse().ok())
.unwrap_or(5),
poll_interval_ms: config.queue_poll_interval_ms,
batch_size: config.queue_batch_size,
max_attempts: config.queue_max_attempts,
}
}
}
@@ -54,15 +45,19 @@ impl SqliteEventQueue {
})
}
pub async fn create_publisher(pool: SqlitePool) -> anyhow::Result<Arc<dyn EventPublisher>> {
let q = Self::create(pool, DbEventQueueConfig::from_env()).await?;
pub async fn create_publisher(
pool: SqlitePool,
config: &config::EventsConfig,
) -> anyhow::Result<Arc<dyn EventPublisher>> {
let q = Self::create(pool, DbEventQueueConfig::from_config(config)).await?;
Ok(Arc::new(q))
}
pub async fn create_channel(
pool: SqlitePool,
config: &config::EventsConfig,
) -> anyhow::Result<(Arc<dyn EventPublisher>, Arc<dyn EventConsumer>)> {
let q = Self::create(pool, DbEventQueueConfig::from_env()).await?;
let q = Self::create(pool, DbEventQueueConfig::from_config(config)).await?;
Ok((Arc::new(q.clone()), Arc::new(q)))
}
}