| Crates.io | wait_utils |
| lib.rs | wait_utils |
| version | 0.1.3 |
| created_at | 2025-01-17 09:08:21.051779+00 |
| updated_at | 2025-01-20 04:00:28.310297+00 |
| description | Utilities for implementing wait loops using varies wait strategies |
| homepage | https://github.com/marvin-hansen/buildutils |
| repository | https://github.com/marvin-hansen/buildutils |
| max_upload_size | |
| id | 1520436 |
| size | 42,699 |
A Rust utility crate providing flexible waiting strategies for services and containers. This crate helps you implement reliable service health checks and startup conditions in your applications.
Add this to your Cargo.toml:
[dependencies]
wait_utils = "0.1.0"
use wait_utils::wait_strategies::wait_until_http_health_check;
let health_url = "http://localhost:8080/health";
let timeout_secs = 30;
match wait_until_http_health_check(true, health_url, &timeout_secs) {
Ok(_) => println!("Service is healthy!"),
Err(e) => eprintln!("Health check failed: {}", e),
}
use wait_utils::wait_strategies::wait_until_grpc_health_check;
async fn check_grpc_health() {
let health_url = "http://localhost:50051";
let timeout_secs = 30;
match wait_until_grpc_health_check(true, health_url, &timeout_secs).await {
Ok(_) => println!("gRPC service is healthy!"),
Err(e) => eprintln!("gRPC health check failed: {}", e),
}
}
use wait_utils::wait_strategies::wait_until_console_output;
let container_id = "your_container_id";
let expected_output = "Server started successfully";
let timeout_secs = 60;
match wait_until_console_output(true, container_id, expected_output, &timeout_secs) {
Ok(_) => println!("Found expected output!"),
Err(e) => eprintln!("Failed to find expected output: {}", e),
}
All waiting strategies return a Result<(), WaitStrategyError>. The WaitStrategyError type provides detailed error messages when waiting conditions are not met within the specified timeout.
Contributions are welcome! Feel free to:
This project is licensed under the MIT license.