feat: add persistence for last deployment path in Nginx handler

This commit is contained in:
2026-06-16 11:09:24 +00:00
parent 3c2cda88f1
commit 24d3f46a5c
3 changed files with 84 additions and 6 deletions

View File

@@ -6,7 +6,7 @@ use nxmesh_proto::{
agent_message::Payload::ConfigUpdateResult as ConfigUpdateResultPayload, command::Command,
command_result,
};
use tracing::warn;
use tracing::{info, warn};
use crate::{
config::settings::NginxSettings,
@@ -106,6 +106,9 @@ impl OnConfigUpdateHandler for NginxMasterMessageHandlerImpl {
}
// apply reload on the root config
self.command_handler.reload(Some(&root_config_path)).await?;
// persist deployment path so Reload/Test commands survive agent restarts
self.fs_handler.save_last_deployment(&root_config_path).await?;
info!("Persisted last deployment path: {}", root_config_path);
// Reply the master to confirm the config update is successful
self.master_handler
.send_message_to_master(nxmesh_proto::AgentMessage {
@@ -141,17 +144,25 @@ impl OnCommandHandler for NginxMasterMessageHandlerImpl {
message_id: message_id.to_string(),
payload: None,
};
// load the last known deployment path for use with Reload/Test commands
let last_config_path = self.fs_handler.load_last_deployment().await?;
let result: command_result::Result = match command {
// TODO: should use the previous config path
Command::Reload(_) => {
let result = self.command_handler.reload(None).await;
let result = self
.command_handler
.reload(last_config_path.as_deref())
.await;
command_result::Result::ReloadResult(nxmesh_proto::ReloadResult {
success: result.is_ok(),
error_message: result.err().map(|e| e.to_string()).unwrap_or_default(),
})
}
Command::Test(_) => {
let result = self.command_handler.validate(None).await;
let result = self
.command_handler
.validate(last_config_path.as_deref())
.await;
command_result::Result::TestResult(nxmesh_proto::TestResult {
success: result.is_ok(),
error_message: result.err().map(|e| e.to_string()).unwrap_or_default(),