4 releases
0.1.3 | Jan 20, 2025 |
---|---|
0.1.2 | Jan 19, 2025 |
0.1.1 | Jan 19, 2025 |
0.1.0 | Jan 17, 2025 |
#197 in Build Utils
364 downloads per month
Used in 2 crates
17KB
206 lines
Wait Utils
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.
Features
- HTTP Health Checks: Wait for HTTP services to become available
- gRPC Health Checks: Wait for gRPC services to become ready
- Console Output Monitoring: Wait for specific output in container logs
- Timeout Controls: Simple timeout-based waiting with customizable durations
Usage
Add this to your Cargo.toml
:
[dependencies]
wait_utils = "0.1.0"
Examples
HTTP Health Check
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),
}
gRPC Health Check
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),
}
}
Container Console Output
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),
}
Error Handling
All waiting strategies return a Result<(), WaitStrategyError>
. The WaitStrategyError
type provides detailed error messages when waiting conditions are not met within the specified timeout.
Contributing
Contributions are welcome! Feel free to:
- Report issues
- Submit pull requests
- Suggest new features
- Improve documentation
Licence
This project is licensed under the MIT license.
Author
- Marvin Hansen
- Contact: https://deepcausality.com/contact/
- Github GPG key ID: 369D5A0B210D39BC
Dependencies
~5–14MB
~162K SLoC