Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| dc4c23f9d9 | |||
| 3182d57539 |
@@ -152,10 +152,45 @@ async fn get_server_id_by_ip(
|
||||
}
|
||||
}
|
||||
|
||||
/// Broadcasts Docker container information to the monitoring server for service discovery.
|
||||
///
|
||||
/// This function sends the current Docker container configuration to the server
|
||||
/// to register available containers and enable service monitoring. It will
|
||||
/// continuously retry until successful, making it suitable for initial
|
||||
/// registration scenarios.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `base_url` - The base URL of the monitoring server API (e.g., "https://monitoring.example.com")
|
||||
/// * `server_id` - The ID of the server to associate the containers with
|
||||
/// * `container_dto` - Mutable reference to Docker container information for broadcast
|
||||
///
|
||||
/// # Returns
|
||||
///
|
||||
/// * `Ok(())` - When container information is successfully broadcasted to the server
|
||||
/// * `Err(Box<dyn Error + Send + Sync>)` - If an unrecoverable error occurs (though the function typically retries on transient failures)
|
||||
///
|
||||
/// # Behavior
|
||||
///
|
||||
/// This function operates in a retry loop with the following characteristics:
|
||||
///
|
||||
/// - **Retry Logic**: Attempts broadcast every 10 seconds until successful
|
||||
/// - **Mutation**: Modifies the `container_dto` to set the `server_id` before sending
|
||||
/// - **TLS**: Accepts invalid TLS certificates for development environments
|
||||
/// - **Logging**: Provides detailed console output about broadcast attempts and results
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// This function may return an error in the following cases:
|
||||
///
|
||||
/// * **HTTP Client Creation**: Failed to create HTTP client with TLS configuration
|
||||
/// * **Network Issues**: Persistent connection failures to the backend server
|
||||
/// * **Server Errors**: Backend returns non-success HTTP status codes repeatedly
|
||||
/// * **JSON Serialization**: Cannot serialize container data (should be rare with proper DTOs)
|
||||
pub async fn broadcast_docker_containers(
|
||||
base_url: &str,
|
||||
server_id: u16,
|
||||
container_dto: &mut DockerRegistrationDto,
|
||||
container_dto: &DockerRegistrationDto,
|
||||
) -> Result<(), Box<dyn Error + Send + Sync>> {
|
||||
// First get local IP
|
||||
println!("Preparing to broadcast docker containers...");
|
||||
@@ -165,8 +200,8 @@ pub async fn broadcast_docker_containers(
|
||||
.build()?;
|
||||
|
||||
// Prepare registration data
|
||||
let container_dto = container_dto;
|
||||
container_dto.server_id = server_id;
|
||||
let mut broadcast_data = container_dto.clone();
|
||||
broadcast_data.server_id = server_id;
|
||||
|
||||
// Try to register (will retry on failure)
|
||||
loop {
|
||||
|
||||
Reference in New Issue
Block a user