Skip to content

Commit

Permalink
fix mark-backend-lost cli command (#571)
Browse files Browse the repository at this point in the history
  • Loading branch information
rolyatmax authored Jan 23, 2024
1 parent a77959c commit aec1371
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use anyhow::{Context, Result};
use chrono::Utc;
use clap::{Parser, Subcommand};
use colored::Colorize;
use plane_core::{
Expand All @@ -7,6 +8,7 @@ use plane_core::{
BackendState, BackendStateMessage, DockerExecutableConfig, ResourceLimits,
TerminationRequest,
},
drone_state::UpdateBackendStateMessage,
scheduler::{DrainDrone, ScheduleRequest, ScheduleResponse},
state::{
BackendMessage, BackendMessageType, ClusterStateMessage, DroneMessage,
Expand Down Expand Up @@ -523,16 +525,32 @@ async fn main() -> Result<()> {

let mut confirmation = String::new();
stdin.read_line(&mut confirmation)?;
let confirmation = confirmation.trim();
if confirmation != "y" {
println!("skipping backend: {backend}, not marking as lost");
continue;
}

let lost_state_message =
BackendStateMessage::new(BackendState::Lost, cluster.clone(), backend.clone());
let drone = backend_state.drone.clone().unwrap();
let message = UpdateBackendStateMessage {
state: BackendState::Lost,
cluster: cluster.clone(),
backend: backend.clone(),
time: Utc::now(),
drone: drone.clone(),
};

nats.publish_jetstream(&lost_state_message).await?;
println!("marking backend: {backend} as lost");
if let Err(error) = nats.request(&message).await {
tracing::error!(
?error,
?state,
?cluster,
?backend,
?drone,
"Failed to update backend state."
);
}
}
}
}
Expand Down

0 comments on commit aec1371

Please sign in to comment.