Skip to content

Commit

Permalink
Put kafka reader behind feature so we can test without it running
Browse files Browse the repository at this point in the history
  • Loading branch information
Lun4m committed Jul 12, 2024
1 parent 729a6b0 commit 3930622
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions ingestion/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ edition.workspace = true

[features]
integration_tests = []
kafka = []

[dependencies]
axum.workspace = true
Expand Down
1 change: 1 addition & 0 deletions ingestion/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use std::{
use thiserror::Error;
use tokio_postgres::NoTls;

#[cfg(feature = "kafka")]
pub mod kvkafka;
pub mod permissions;
use permissions::{ParamPermitTable, StationPermitTable};
Expand Down
9 changes: 7 additions & 2 deletions ingestion/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
use bb8_postgres::PostgresConnectionManager;
use lard_ingestion::{kvkafka, permissions};
use std::sync::{Arc, RwLock};
use tokio_postgres::NoTls;

#[cfg(feature = "kafka")]
use lard_ingestion::kvkafka;
use lard_ingestion::permissions;

const PARAMCONV: &str = "resources/paramconversions.csv";

#[tokio::main]
Expand Down Expand Up @@ -40,11 +43,13 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
});

// Set up postgres connection pool
let manager = PostgresConnectionManager::new_from_stringlike("LARD_STRING", NoTls)?;
let manager =
PostgresConnectionManager::new_from_stringlike(std::env::var("LARD_STRING")?, NoTls)?;
let db_pool = bb8::Pool::builder().build(manager).await?;

// Spawn kvkafka reader
let kafka_group = args[1].to_string();
#[cfg(feature = "kafka")]
tokio::spawn(kvkafka::read_and_insert(db_pool.clone(), kafka_group));

// Set up and run our server + database
Expand Down
2 changes: 1 addition & 1 deletion integration_tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ debug = []

[dependencies]
lard_api = { path = "../api" }
lard_ingestion = { path = "../ingestion", features = ["integration_tests"] }
lard_ingestion = { path = "../ingestion", features = ["integration_tests", "kafka"] }
chrono.workspace = true
tokio.workspace = true
tokio-postgres.workspace = true
Expand Down

0 comments on commit 3930622

Please sign in to comment.