From 85b56634644d23011ac01fb4de04ba1bf6942695 Mon Sep 17 00:00:00 2001 From: Pete Gadomski Date: Wed, 18 Dec 2024 08:59:42 -0700 Subject: [PATCH] feat: add logging --- Cargo.lock | 18 ++++++++++++++++++ Cargo.toml | 1 + src/lib.rs | 6 ++++++ 3 files changed, 25 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 5c8948f..1d500b3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -69,6 +69,12 @@ dependencies = [ "num-traits", ] +[[package]] +name = "arc-swap" +version = "1.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69f7f8c3906b62b754cd5326047894316021dcfe5a194c8ea52bdd94934a3457" + [[package]] name = "async-trait" version = "0.1.83" @@ -924,6 +930,7 @@ dependencies = [ "pgstac", "pyo3", "pyo3-async-runtimes", + "pyo3-log", "pythonize", "serde_json", "stac", @@ -1092,6 +1099,17 @@ dependencies = [ "pyo3-build-config", ] +[[package]] +name = "pyo3-log" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3eb421dc86d38d08e04b927b02424db480be71b777fa3a56f32e2f2a3a1a3b08" +dependencies = [ + "arc-swap", + "log", + "pyo3", +] + [[package]] name = "pyo3-macros" version = "0.23.3" diff --git a/Cargo.toml b/Cargo.toml index 9f214d1..b8fff79 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,6 +18,7 @@ pyo3-async-runtimes = { version = "0.23.0", features = [ "tokio", "tokio-runtime", ] } +pyo3-log = "0.12.0" pythonize = "0.23.0" serde_json = "1.0.133" stac-api = { version = "0.6.2", features = [ diff --git a/src/lib.rs b/src/lib.rs index fd5ac29..4655426 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -70,6 +70,10 @@ impl Client { .map_err(|err: ::Err| PyValueError::new_err(err.to_string()))?; let manager = PostgresConnectionManager::new(config.clone(), NoTls); pyo3_async_runtimes::tokio::future_into_py(py, async move { + { + // Quick connection to get better errors, bb8 will just time out + let _ = config.connect(NoTls).await.map_err(Error::from)?; + } let pool = Pool::builder().build(manager).await.map_err(Error::from)?; // TODO allow configuration { let connection = pool.get().await.map_err(Error::from)?; @@ -344,6 +348,8 @@ impl From for PyErr { #[pymodule] fn pgstacrs(py: Python<'_>, m: &Bound<'_, PyModule>) -> PyResult<()> { + pyo3_log::init(); + m.add_class::()?; m.add("StacError", py.get_type::())?; m.add("PgstacError", py.get_type::())?;