Skip to content

Commit

Permalink
feat: add logging (#13)
Browse files Browse the repository at this point in the history
Also do a quick pre-connection to throw any errors before we build the
pool. This might be bad from a performance side, so we'll want to see if
there's a better way (@gadomski will open an issue).
  • Loading branch information
gadomski authored Dec 18, 2024
1 parent df59d1d commit 7ff0791
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
18 changes: 18 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
6 changes: 6 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ impl Client {
.map_err(|err: <Config as FromStr>::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)?;
Expand Down Expand Up @@ -344,6 +348,8 @@ impl From<Error> for PyErr {

#[pymodule]
fn pgstacrs(py: Python<'_>, m: &Bound<'_, PyModule>) -> PyResult<()> {
pyo3_log::init();

m.add_class::<Client>()?;
m.add("StacError", py.get_type::<StacError>())?;
m.add("PgstacError", py.get_type::<PgstacError>())?;
Expand Down

0 comments on commit 7ff0791

Please sign in to comment.