feat: Update zinit-client dependency to 0.4.0

- Upgrade `zinit-client` dependency to version 0.4.0 across all
  relevant crates. This resolves potential compatibility issues
  and incorporates bug fixes and improvements from the latest
  release.

- Improve error handling and logging in `zinit-client` and
  `service_manager` to provide more informative feedback and
  prevent potential hangs during log retrieval.  Add timeout to
  prevent indefinite blocking on log retrieval.

- Update `publish-all.sh` script to correctly handle the
  `service_manager` crate during publishing.  Improves handling of
  special cases in the publishing script.

- Add `zinit-client.workspace = true` to `Cargo.toml` to ensure
  consistent dependency management across the workspace.  This
  ensures the correct version of `zinit-client` is used everywhere.
This commit is contained in:
Mahmoud-Emad
2025-07-10 11:27:59 +03:00
parent fc2830da31
commit 423b7bfa7e
7 changed files with 84 additions and 35 deletions

View File

@@ -18,7 +18,7 @@ thiserror = "2.0.12"
tokio = { version = "1.45.0", features = ["full"] }
# Zinit client
zinit-client = "0.3.0"
zinit-client = "0.4.0"
# Rhai integration
rhai = { version = "1.12.0", features = ["sync"] }

View File

@@ -149,34 +149,51 @@ impl ZinitClientWrapper {
// Get logs with real implementation
pub async fn logs(&self, filter: Option<String>) -> Result<Vec<String>, ZinitError> {
use futures::StreamExt;
use tokio::time::{timeout, Duration};
// The logs method requires a follow parameter and filter
let follow = false; // Don't follow logs, just get existing ones
let mut log_stream = self.client.logs(follow, filter).await?;
let mut logs = Vec::new();
// Collect logs from the stream with a reasonable limit
// Collect logs from the stream with a reasonable limit and timeout
let mut count = 0;
const MAX_LOGS: usize = 1000;
const LOG_TIMEOUT: Duration = Duration::from_secs(5);
while let Some(log_result) = log_stream.next().await {
match log_result {
Ok(log_entry) => {
// Convert LogEntry to String using Debug formatting
logs.push(format!("{:?}", log_entry));
count += 1;
if count >= MAX_LOGS {
// Use timeout to prevent hanging
let result = timeout(LOG_TIMEOUT, async {
while let Some(log_result) = log_stream.next().await {
match log_result {
Ok(log_entry) => {
// Convert LogEntry to String using Debug formatting
logs.push(format!("{:?}", log_entry));
count += 1;
if count >= MAX_LOGS {
break;
}
}
Err(e) => {
log::warn!("Error reading log entry: {}", e);
break;
}
}
Err(e) => {
log::warn!("Error reading log entry: {}", e);
break;
}
}
})
.await;
// Handle timeout - this is not an error, just means no more logs available
match result {
Ok(_) => Ok(logs),
Err(_) => {
log::debug!(
"Log reading timed out after {} seconds, returning {} logs",
LOG_TIMEOUT.as_secs(),
logs.len()
);
Ok(logs)
}
}
Ok(logs)
}
}