Skip to content

Commit 51d62a1

Browse files
committed
fix: refresh app state on task completion for both success and failure
Previously, app details were only refreshed on successful task completion via UpdateAppDataHandler. When tasks failed (e.g., blueprint command errors), the state machine jumped directly to SetFailed, leaving stale container IDs in the app state. Now TaskCompletionHandler always calls inspect_app() and update_app() before completing, ensuring app state reflects current Docker container information regardless of task outcome. Closes #605
1 parent 59076d1 commit 51d62a1

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

scotty/src/docker/state_machine_handlers/task_completion_handler.rs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use scotty_core::{notification_types::Message, tasks::task_details::State};
44
use tokio::sync::RwLock;
55
use tracing::instrument;
66

7-
use crate::state_machine::StateHandler;
7+
use crate::{docker::find_apps::inspect_app, state_machine::StateHandler};
88

99
use super::context::Context;
1010

@@ -78,23 +78,29 @@ where
7878
CompletionType::Failure => (State::Failed, "Operation failed for", true),
7979
};
8080

81-
// Use the shared helper - single source of truth for task completion
82-
let app_name = context.read().await.app_data.name.clone();
83-
let status_msg = format!("{} operation for app '{}'", status_msg_prefix, app_name);
81+
// Refresh app state to get current Docker container info
82+
{
83+
let ctx = context.read().await;
84+
let docker_compose_path = std::path::PathBuf::from(&ctx.app_data.docker_compose_path);
8485

85-
context
86-
.read()
87-
.await
88-
.complete_task(target_state, status_msg, use_error_status)
89-
.await;
86+
let app_data = inspect_app(&ctx.app_state, &docker_compose_path).await?;
87+
ctx.app_state.apps.update_app(app_data).await?;
88+
89+
// Use the shared helper - single source of truth for task completion
90+
let app_name = ctx.app_data.name.clone();
91+
let status_msg = format!("{} operation for app '{}'", status_msg_prefix, app_name);
92+
93+
ctx.complete_task(target_state, status_msg, use_error_status)
94+
.await;
95+
} // Drop ctx read lock here
9096

9197
// Send notifications in a dedicated thread (for both success and failure)
9298
if self.notification.is_some() {
9399
tokio::spawn({
94100
let notification = self.notification.clone();
95101
let completion_type = self.completion_type;
102+
let context = context.clone();
96103
async move {
97-
let context = context.clone();
98104
let context = context.read().await;
99105

100106
if let (Some(app_settings), Some(notification)) =

0 commit comments

Comments
 (0)