refactor: adapters configured from config crate
This commit is contained in:
@@ -4,6 +4,7 @@ version = "0.1.0"
|
||||
edition.workspace = true
|
||||
|
||||
[dependencies]
|
||||
config = { workspace = true }
|
||||
sqlx = { workspace = true, features = ["macros", "chrono"] }
|
||||
|
||||
domain = { workspace = true }
|
||||
|
||||
@@ -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)))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user