json as string
This commit is contained in:
@@ -193,26 +193,37 @@ pub async fn broadcast_docker_containers(
|
||||
server_id: u16,
|
||||
container_dto: &DockerRegistrationDto,
|
||||
) -> Result<(), Box<dyn Error + Send + Sync>> {
|
||||
// First get local IP
|
||||
println!("Preparing to broadcast docker containers...");
|
||||
// Create HTTP client for registration
|
||||
let client = Client::builder()
|
||||
.danger_accept_invalid_certs(true)
|
||||
.build()?;
|
||||
|
||||
// Prepare registration data
|
||||
let mut broadcast_data = container_dto.clone();
|
||||
broadcast_data.server_id = server_id;
|
||||
// Create a new struct that matches the server's expected format
|
||||
#[derive(Serialize)]
|
||||
struct ServiceDiscoveryRequest {
|
||||
#[serde(rename = "Server_id")]
|
||||
server_id: u16,
|
||||
#[serde(rename = "Containers")]
|
||||
containers: String, // JSON string instead of Vec
|
||||
}
|
||||
|
||||
// Serialize containers to JSON string
|
||||
let containers_json = serde_json::to_string(&container_dto.containers)
|
||||
.map_err(|e| format!("Failed to serialize containers: {}", e))?;
|
||||
|
||||
let broadcast_data = ServiceDiscoveryRequest {
|
||||
server_id,
|
||||
containers: containers_json,
|
||||
};
|
||||
|
||||
// Try to register (will retry on failure)
|
||||
loop {
|
||||
println!("Attempting to broadcast containers...");
|
||||
let url = format!("{}/monitoring/service-discovery", base_url);
|
||||
match client.post(&url).json(&container_dto).send().await {
|
||||
match client.post(&url).json(&broadcast_data).send().await {
|
||||
Ok(resp) if resp.status().is_success() => {
|
||||
println!(
|
||||
"✅ Successfully broadcasted following docker container: {:?}",
|
||||
container_dto
|
||||
"✅ Successfully broadcasted docker containers for server {}",
|
||||
server_id
|
||||
);
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user