Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/download_progress_bar/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ version.workspace = true
[dependencies]
anyhow = { workspace = true }
indicatif = { workspace = true }
postgresql_embedded = { path = "../../postgresql_embedded" }
postgresql_embedded = { path = "../../postgresql_embedded", features = ["indicatif"] }
postgresql_extensions = { path = "../../postgresql_extensions" }
tracing = { workspace = true }
tracing-indicatif = { workspace = true }
Expand Down
5 changes: 4 additions & 1 deletion postgresql_archive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ tempfile = { workspace = true }
thiserror = { workspace = true }
tokio = { workspace = true, features = ["full"], optional = true }
tracing = { workspace = true, features = ["log"] }
tracing-indicatif = { workspace = true }
tracing-indicatif = { workspace = true, optional = true }
url = { workspace = true }
zip = { workspace = true }

Expand All @@ -56,6 +56,9 @@ blocking = ["dep:tokio"]
github = [
"dep:serde_json",
]
indicatif = [
"dep:tracing-indicatif"
]
maven = [
"dep:quick-xml",
"md5",
Expand Down
11 changes: 6 additions & 5 deletions postgresql_archive/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,12 @@ uses.

The following features are available:

| Name | Description | Default? |
|--------------|----------------------------|----------|
| `blocking` | Enables the blocking API | No |
| `native-tls` | Enables native-tls support | Yes |
| `rustls-tls` | Enables rustls-tls support | No |
| Name | Description | Default? |
|--------------|----------------------------------|----------|
| `blocking` | Enables the blocking API | No |
| `indicatif` | Enables tracing-indcatif support | No |
| `native-tls` | Enables native-tls support | Yes |
| `rustls-tls` | Enables rustls-tls support | No |

### Configurations

Expand Down
14 changes: 10 additions & 4 deletions postgresql_archive/src/repository/github/repository.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ use std::env;
use std::io::Write;
use std::str::FromStr;
use std::sync::LazyLock;
use tracing::{debug, instrument, warn, Span};
use tracing::{debug, instrument, warn};
#[cfg(feature = "indicatif")]
use tracing_indicatif::span_ext::IndicatifSpanExt;

use url::Url;
Expand Down Expand Up @@ -225,13 +226,18 @@ impl Repository for GitHub {
debug!("Downloading archive {}", asset.browser_download_url);
let request = client.get(&asset.browser_download_url);
let response = request.send().await?.error_for_status()?;
let span = Span::current();
let content_length = response.content_length().unwrap_or_default();
#[cfg(feature = "indicatif")]
let span = tracing::Span::current();
#[cfg(feature = "indicatif")]
{
let content_length = response.content_length().unwrap_or_default();
span.pb_set_length(content_length);
}
let mut bytes = Vec::new();
let mut source = response.bytes_stream();
span.pb_set_length(content_length);
while let Some(chunk) = source.next().await {
bytes.write_all(&chunk?)?;
#[cfg(feature = "indicatif")]
span.pb_set_position(bytes.len() as u64);
}
debug!(
Expand Down
14 changes: 10 additions & 4 deletions postgresql_archive/src/repository/maven/repository.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ use semver::{Version, VersionReq};
use std::env;
use std::io::Write;
use std::sync::LazyLock;
use tracing::{debug, instrument, warn, Span};
use tracing::{debug, instrument, warn};
#[cfg(feature = "indicatif")]
use tracing_indicatif::span_ext::IndicatifSpanExt;

static USER_AGENT: LazyLock<String> = LazyLock::new(|| {
Expand Down Expand Up @@ -132,13 +133,18 @@ impl Repository for Maven {
debug!("Downloading archive {archive_url}");
let request = client.get(&archive_url);
let response = request.send().await?.error_for_status()?;
let span = Span::current();
let content_length = response.content_length().unwrap_or_default();
#[cfg(feature = "indicatif")]
let span = tracing::Span::current();
#[cfg(feature = "indicatif")]
{
let content_length = response.content_length().unwrap_or_default();
span.pb_set_length(content_length);
}
let mut bytes = Vec::new();
let mut source = response.bytes_stream();
span.pb_set_length(content_length);
while let Some(chunk) = source.next().await {
bytes.write_all(&chunk?)?;
#[cfg(feature = "indicatif")]
span.pb_set_position(bytes.len() as u64);
}
debug!("Archive {archive_url} downloaded: {}", bytes.len(),);
Expand Down
3 changes: 3 additions & 0 deletions postgresql_embedded/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ default = [
]
blocking = ["tokio"]
bundled = ["postgresql_archive/github"]
indicatif = [
"postgresql_archive/indicatif",
]
native-tls = [
"postgresql_archive/native-tls",
"sqlx/tls-native-tls",
Expand Down
1 change: 1 addition & 0 deletions postgresql_embedded/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ The following features are available:
|--------------|----------------------------------------------------------|----------|
| `bundled` | Bundles the PostgreSQL archive into the resulting binary | No |
| `blocking` | Enables the blocking API; requires `tokio` | No |
| `indicatif` | Enables tracing-indcatif support | No |
| `native-tls` | Enables native-tls support | Yes |
| `rustls-tls` | Enables rustls-tls support | No |
| `theseus` | Enables theseus PostgreSQL binaries | Yes |
Expand Down
Loading