wait_utils

Crates.iowait_utils
lib.rswait_utils
version0.1.3
created_at2025-01-17 09:08:21.051779+00
updated_at2025-01-20 04:00:28.310297+00
descriptionUtilities for implementing wait loops using varies wait strategies
homepagehttps://github.com/marvin-hansen/buildutils
repositoryhttps://github.com/marvin-hansen/buildutils
max_upload_size
id1520436
size42,699
Marvin Hansen (marvin-hansen)

documentation

README

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

Commit count: 88

cargo fmt